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 Making Decisions in Your Code with Conditional Statements Write an 'if' Statement

Steven White
Steven White
2,372 Points

Challenge: timeout of 2000ms exceeded.

Timeout error appears when running if statement. Code executes properly in jSFiddle and console.

script.js
const isAdmin = true;
const isStudent = false;
let message;

if ( isAdmin === true ) {
  message = alert("Welcome admin");
}

2 Answers

Steven, I think since the challenge is just looking for you to assign the "Welcome admin" value to the message variable and technically the alert() function doesn't return anything to assign to the message variable then that is why you are getting the error. If you just assign the "Welcome admin" value to the message variable then you'd be able to pass the challenge.

if ( isAdmin === true ) {
  message = "Welcome admin";
}
Steven White
Steven White
2,372 Points

Thank you for the response!

Turns out I was overthinking the problem. Suggestion, with slight modification, worked to pass this challenge and next two ( else if and else ). Code which passed the three challenges is as follows:

<p>const isAdmin = false;
const isStudent = false;
let message;

if ( isAdmin ) {
  message = 'Welcome admin';
} else if ( isStudent ) {
  message = 'Welcome student';
} else {
  message = "Access denied";
}
</p>
```/html