【发布时间】:2017-09-08 09:06:17
【问题描述】:
需要帮助运行这两个脚本,似乎只有一个在运行,我得到一个名称,但它只是停止运行。帮助将不胜感激。我一直在使用 java 和 C++,所以这自然让我感到困惑。谢谢
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="jstut.js"></script>
<style type="text/css">
body {font-size: 1.6em;}
.hidden {display:none;}
.show {display:inline !important;}
button {
border: 2px solid black; background: #E5E4E2;
font-size: .5em; font-weight: bold; color: black;
padding: .8em 2em;
margin-top: .4em;
}
</style>
</head>
<body>
<p id="sayHello"></p>
<script>
var yourName = prompt("What is your name?");
if(yourName!= null){
document.getElementById("sayHello").innerHTML = "Hello " + yourName;
}else{
alert("Please enter your name correctly");
}
</script>
<script>
var myAge = prompt("What is your age");
if(myAge < 4){
document.write ("You should be in preschool";
}else if(my age > 4 && <18){
document.write("You should be in public private school");
}else if (my age >18 && <24){
document.write("You should be in college");
}
else{ document.write(your in the work force now);}
</script>
</body>
</html>
【问题讨论】:
-
在浏览器中按 F12 并查看 Console,您会看到一个错误,告诉您这里缺少
):("You should be in preschool"; -
学习使用一些工具来验证你的 JS 语法:stackoverflow.com/questions/2120093/…
-
另外,
document.write(your in the work force now);应该是document.write("your in the work force now"); -
@Henry 从技术上讲,它应该是“
you're现在在工作中。” -
@Albzi 很惊讶你没有指出技术上
What is your age缺少?
标签: javascript html