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 Comparison Operators

Shezan Kazi
Shezan Kazi
10,807 Points

string.includes Method

Hi,

I used this method for the 2nd challenge:

var answer = prompt("What is the best programming language?");
var answer = answer.toLowerCase();
if (answer.includes("javascript")) {
  alert("You are correct!");
}

Using workspaces this worked out fine. The challenge did not accept it. Is it bad practice to use functions, that are still prototyped on MDN?

Also the challenge did not accept the toLowerCase() Method, which I chose, because a user might not type JavaScript but javascript.

//Fixed Code Presentation

3 Answers

The challenge is asking that you create a conditional statement to check if the answer is equal to "JavaScript". Your code should look like this.

var answer = prompt("What is the best programming language?");
if(answer === "JavaScript"){
  alert("You are correct");
}

I hope this helps.

Shezan Kazi
Shezan Kazi
10,807 Points

I eventually used exactly this code. But in "real-life" would one choose the approach the challenge requires or something like I used? (I tried to reduce the risk of user input errors with very primitive means :-) )

Shezan Kazi :

Your approach is the correct one. Minimizing user input errors.

But the challange says you have to do it It's way.

So in the future: do as the challange question or statement asks.

But if you find another way you would tackle the problem at hand - use your way (in real life) :) and don't forget to share your ideas with the community.

Good job.

Happy Coding!!!

nWEBd

lee F
lee F
1,564 Points

Can't really give you an explanation, but I would think this is correct:

var answer = prompt("What is the best programming language?");
answer = answer.toLowerCase();
if (answer === ("javascript")) {
  alert("You are correct!");}  
Shezan Kazi
Shezan Kazi
10,807 Points

Ok great. Thanks for the feedback. Then I will dive back into MDN and see what other fun methods I can come up with :-)