gpt4 book ai didi

javascript - 使用 Javascript 对话框获取和、积、差和商 + 显示结果

转载 作者:行者123 更新时间:2023-12-03 08:17:49 30 4
gpt4 key购买 nike

我正在尝试开发一个Javascript程序,它会提示用户输入两个整数,然后显示这两个整数的和、乘积、差和商。现在它只显示总和。我实际上不知道乘法、减法和除法命令是否正在执行。这是 jsfiddle 的链接:http://jsfiddle.net/xsdztwoc/

代码:

<!DOCTYPE html>
<html>
<head>
<meta charset = "utf-8">
<title>Integer Application</title>
<script>

var firstNumber; // first string entered by user
var secondNumber; // second string entered by user
var number1; // first number to add
var number2; // second number to add
var sum; // sum of number1 and number2
var product; //product of number1 and number2
var difference; //difference of number1 and number2
var quotient; //quotient of number1 and number2

// read in first number from user as a string
firstNumber = window.prompt( "Enter first integer" );

// read in second number from user as a string
secondNumber = window.prompt( "Enter second integer" );

// convert numbers from strings to integers
number1 = parseInt( firstNumber );
number2 = parseInt( secondNumber );

sum = number1 + number2; // add the numbers
product = number1 * number2; //multiply the integers
difference = number1 - number2; //subtract the integers
quotient = number1 / number2; //divide the integers

// display the results
document.writeln( "<h1>The sum is " + sum + "</h1>" );
document.writeIn( "<h1>The product is " + product + "</h1>");
document.writeIn
( "<h1>The difference is " + difference + "</h1>");
document.writeIn( "<h1>The quotient is " + quotient + "</h1>");
</script>
</head><body></body>
</html>

感谢您提供的任何帮助!

最佳答案

jsFiddle

问题似乎只是您正在使用 document.writeIn 但这不是一个函数。您要使用: document.writeln 代表 writeLine

JS

// display the results
document.writeln( "<h1>The sum is " + sum + "</h1>" );
document.writeln( "<h1>The product is " + product + "</h1>");
document.writeln( "<h1>The difference is " + difference + "</h1>");
document.writeln( "<h1>The quotient is " + quotient + "</h1>");

关于javascript - 使用 Javascript 对话框获取和、积、差和商 + 显示结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33863522/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com