Javascript Age Document.write,帮助打印18岁及以上和50岁及以上的语句

Javascript Age Document.write, help print out both statements 18 and over and 50 and over?

本文关键字:50岁 语句 18岁 Document Age write 打印 帮助 Javascript      更新时间:2024-04-27

我需要帮助打印出基于输入年龄的消息。如果我输入55岁,它会打印"你可以开车!"answers"必须进行体检"。如果我输入20岁,它只会打印第一条信息。

这是我迄今为止写的代码:

<script>
function Driving() {
var Drive;
age = prompt("Please, put in your age");

if (age >= 18){
    document.write("You're okay to drive!");
}
else if (age == 50){
document.write("Must have medical checkup.");
} else {
    document.write("Too young to drive.");
    }
return;
}
</script>
</head>
<body onLoad="Driving()">
</body>
</html>

您必须嵌套if语句。

if (age >= 18) {
  document.write("Your okay to drive!<br>");
  if (age >= 50) {
    document.write("Must have medical checkup.");
  }
} else {
  document.write("Too young to drive.");
}

https://jsfiddle.net/cowdd/1hsjy8j3/