need help running both scripts, only one seems to run, I get the name one to work but than it just stops running. help would be appreciated. I've been using java and C++ so this is naturally confusing to me.
<!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>
You missed a )
on this line: document.write ("You should be in preschool";
There were also a few other mistakes that were pointed out by @Albzi, @Alex K., and @Henry in the comments. These guys helped a lot.
Code changes:
)
in this line: document.write ("You should be in preschool";
if(my age > 4 && <18)
with if (myAge>4 && myAge<18)
. Same goes for the line below.my age
with 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>