需要帮助运行这两个脚本,似乎只有一个在运行,我得到了一个可以运行的名称,但它只是停止运行。如有帮助,将不胜感激。我一直在使用 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>
最佳答案
您错过了)
在此行:document.write ("You should be in preschool";
@Albzi、@Alex K. 和 @Henry 在评论中还指出了一些其他错误。这些人帮了很多忙。
代码更改:
- 已修复
)
的问题在此行中:document.write ("You should be in preschool";
- 已替换
if(my age > 4 && <18)
与if (myAge>4 && myAge<18)
。下面的行也是如此。 - 已替换
my age
与myAge
- 更正拼写
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;
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="jstut.js"></script>
</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 (myAge > 4 && myAge < 18) {
document.write("You should be in public private school");
} else if (myAge > 18 && myAge < 24) {
document.write("You should be in college");
} else {
document.write("You're in the work force now");
}
</script>
</body>
</html>
关于javascript - 刚刚启动java脚本,需要帮助运行两个脚本,似乎只有一个运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43371994/