【发布时间】:2019-11-30 20:21:19
【问题描述】:
方向 在 index.html 和 script.js 文件中,添加以下内容:
Link your JavaScript file to your HTML file.
Create a function named numberCalculation
Within the function, create two variables:
The first variable should be named number1
Set it to 45
The second variable should be named number2
Set it to 78
Create another variable named multiplyNumbers and set it to number1 times number2
Create an if statement that checks to see if multiplyNumbers is less than 2000
If it is, add an alert that says "I wish it was a bigger number"
If the variable multiplyNumbers is not less than 2000, alert "That's more like it!"
Below the definition of the above function, add a call to it: numberCalculation(). As a result, when the page is loaded, it should produce an alert with one of the above messages.
我知道它很明显我只是没有注意到它
script.js:
function numberCalculation(){
var number1=45;
var number2=78;
var multiplyNumbers= number1*number2;
if (multiplyNumbers<2000);{
alert("I wish it was a bigger number");
if (multiplyNumbers>2000);
alert("That's more like it!");
}
numberCalculation();
}
我应该得到“这更像是它!”警报,但我没有得到任何提示
【问题讨论】:
-
您的开发工具中应该出现错误。 (F12) 一旦你修复它,你很快就会遇到第二个类似的错误。
-
如果此代码实际运行没有问题,您会感到惊讶 - 您还应该删除您放在
if条件和相应代码块之间的; -
2000 年会发生什么?
-
@epascarello i.giphy.com/media/lN9wakZ84b8tn7lUwy/giphy.webp
标签: javascript html function var