我必须创建一个要求用户输入两个数字的代码。程序需要将这两个数字相乘,然后在显示的消息中显示答案。即:5 x 7 是 35!(假设用户输入的数字是 5 和 7。)
这是我现在拥有的代码。
<title></title>
<script type="text/javascript">
var num1 = 0;
var num2 = 0;
var calculatedNum = 0;
function calculation() {
//create a integer variable called num2
//Purpose: second variable
var num2 = 0; // integer second variable
//create a integer variable called calculatedNum
//Purpose: num1 x num2
var calculatedNum = 0; // integer num1 x num2
//ask user '"Please type the first number"'
//and put the answer in num1
num1 = prompt("Please type the first number");
//ask user '"Please type the second number."'
//and put the answer in num2
num2 = prompt("Please type the second number.");
//Tell user: num1 + "x" + num2 + "=" + calculatedNum
alert (num1 + "x" + num2 + "=" + calculatedNum);
} // end calculation function
}end program
</script>