Reputation: 19
Title is self explanatory i have this JS code (going back to basics) extremely simple but i can't for the life of me figure out why i won't run. All i know is the developer console says unexpected token "{" on line 21, but that's what opens my if statement.
enter code here
<!Doctype html>
<html land="en">
<head>
<meta charset="utf-8" />
<title>Chapter 2, Example 7</title>
</head>
<body>
<script type="text/javascript">
var myAge = parseInt(prompt ("Enter your age", 30),10);
if (myAge >= 0 && myAge <= 100) {
document.write("myAge is between 0 and 10<br />");
}
if (!(myAge >= 0 && myAge <= 10) ) {
document.write("myAge is NOT between 0 and 10<br />");
}
if (myAge >= 80 || myAge <= 10) {
document.write("myAge is 80 or above OR 10 or below<br />");
}
if ( (myAge >= 30 && myAge <= 39 || (myAge >= 80 && myAge <= 89) ) {
document.write("myAge is between 30 and 39 or myAge is " +
"is between 80 and 89");
}
</script>
</body>
</html>
Upvotes: -1
Views: 56
Reputation: 386746
change
if ( (myAge >= 30 && myAge <= 39 || (myAge >= 80 && myAge <= 89) ) {
to
if ( (myAge >= 30 && myAge <= 39) || (myAge >= 80 && myAge <= 89) ) {
or if you like, keyword operator precedence:
if (myAge >= 30 && myAge <= 39 || myAge >= 80 && myAge <= 89) {
and a little hint
if (myAge >= 0 && myAge <= 100) { // <-- or this should be 10 ...?
document.write("myAge is between 0 and 10<br />");
} // ^^
// should be 100?
Upvotes: 0
Reputation: 10756
Your missing a parenthesis on this line
if ((myAge >= 30 && myAge <= 39 || (myAge >= 80 && myAge <= 89)) {
should be
if ((myAge >= 30 && myAge <= 39) || (myAge >= 80 && myAge <= 89)) {
Upvotes: 2