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 trial

JavaScript JavaScript Basics (Retired) Making Decisions with Conditional Statements Add an Else If Clause

Aaron Jones
Aaron Jones
637 Points

i dont know what to do here? Need some help!

The question asked, " Add an else if clause that tests to see if the isStudent variable is true. If it is then open an alert dialog with the message 'Welcome student'?

script.js
var isAdmin = false;
var isStudent = true;

if (
index.html
<!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>
Mike Shannon
Mike Shannon
7,515 Points

It looks like your snippet is missing the first piece which is

if ( isAdmin ) {
    alert('Welcome administrator').

With the previous statement in place, you'll want to follow the same structure. Try something like this.

else if (condition is true){
  alert('print this text')
}
Aaron Jones
Aaron Jones
637 Points

that didn't work idk why its not working

Mike Shannon
Mike Shannon
7,515 Points

Make sure you're paying attention the the case-sensitivity of the alert statement it wants you to put out. I believe it has to be exactly 'Welcome student' to satisfy the challenge

Also, remember that the statement can be (isStudent === true) or simplified to (isStudent)

1 Answer

Peter Vanderlind de Oliveira
Peter Vanderlind de Oliveira
7,376 Points

Hi :)

Try this instead:

var isAdmin = false; var isStudent = true;

if ( isAdmin ) { alert('Welcome administrator'); }

else if ( isStudent ) { alert("Welcome Student"); }

The following link helped me complete the challenge: https://www.w3schools.com/js/js_if_else.asp