Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAli Corlett
Courses Plus Student 1,359 PointsJavaScript Basics - Boolean - if, if else, else. test issue
Hi, I am have added correctly the first two steps and am tripping up on the third. The final else statement to represent if both answers for administrator and student are false then the alert for 'who are you' value should be returned.
Where am I going wrong? Ali
var isAdmin = false; var isStudent = false;
if ( isAdmin ) { alert('Welcome administrator');
} else if (isStudent) { alert('Welcome student');
} else ({isAdmin} + {isStudent}) { alert('Who are you?');
var isAdmin = false;
var isStudent = false;
if ( isAdmin ) {
alert('Welcome administrator');
} else if (isStudent) {
alert('Welcome student');
} else ({isAdmin} + {isStudent}) {
alert('Who are you?');
}
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JavaScript Basics</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
3 Answers
Manish Giri
16,266 PointsThe else
block is the final block in a chain of if-else-if-else
statements. If none of the prior if
or else-if
statements execute, then the else
block will execute. So you shouldn't have any conditions in the else
block.
The general structure is like this -
if(someCondition) {
// do this
}
else if(someOtherCondition) {
// do this instead
}
else {
// nothing above matched, so do this
}
Fix your else
block to remove the condition -
else ({isAdmin} + {isStudent}) {
alert('Who are you?');
}
Ali Corlett
Courses Plus Student 1,359 PointsThis didn't help me. I don't know what the correct final condition should be, I get a syntax error. I've tried these. The more I guess the more confused I get as this is the first time I've tried this in JavaScript. Can you tell me what the final condition should be please?
} else (=true) { alert('Who are you?'); }
} else { alert('Who are you?'); }
} else ({isAdmin} + {isStudent}) { alert('Who are you?'); }
Ali Corlett
Courses Plus Student 1,359 PointsSolved. Finally.
} else alert('Who are you?');{ }