That said I am trying to create a loop that takes two integers and multiplys them by using a loop to do addition.
I have already done an addition and subtraction that takes 2 user inputs and does the math.
Now I am trying to take user input and instead of doing a simple 3 * 4 loop it so it goes 3 + 3 + 3 + 3.
This is what I have so far...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Multiplying</title>
<meta http-equiv="content-type"
content="text/html;charset=utf-8" />
<script type="text/javascript">
var $ = function ( id ) {
return document.getElementById( id );
}
var display_sum = function () {
var addNum1 = parseInt( $("addNum1").value );
var multiNum = parseInt( $("multiNum").value );
$("sum").value = "";
if (isNaN(addNum1)){
alert("First number is not a valid number");
} else if (isNaN(multiNum)){
alert("Second number is not a valid number");
} else {
var sum =
}
$("sum").value = sum;
}
window.onload = function(){
$("calculate").onclick = display_sum;
}
</script>
</head>
<body>
<div>
<h1>Multiplying 2 numbers</h1>
<p>Enter the 2 numbers you wish to multiply (one in each box)</p>
<input type="text" value=" " id="addNum1"/><br/>
<input type="text" value=" " id="multiNum"/><br/>
<input type="text" value="Total" id="sum"/><br/>
<input type="button" id="calculate" value="Calculate"/><br/>
</div>
</body>
</html>
I have edited out my loops because thus far all I have managed to do is increment the addNum1. ie I put in 3 * 4 my loops would make 7. So if anyone could just tell me which loop to use or if I need another function to do it or what I would really appreaciate any help.

New Topic/Question
Reply


MultiQuote



|