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 The Conditional Challenge

Marcell Ciszek
Marcell Ciszek
7,255 Points

Why will this code not work?

let quiz3 = Number(prompt('please enter the best football team in the world, both the name and the year they was created!!')); if (quiz3 === 'legia ' && 1916){ alert('correct') } else { alert('wrong!!'); }

Why are you using Number()? That will return NaN.

Marcell Ciszek
Marcell Ciszek
7,255 Points

I thought Prompt only can store strings, and that you have to change the string to a number. But please explain for me, i know this code has nothing to do with the exercise i just wanted to try it but it didn't work.

Yes prompt will return a string. But your answer is also a string so no conversion necessary.

1 Answer

Mino Karadzhov
Mino Karadzhov
8,167 Points

Hello, Marcel :) Just for a future reference, please keep in mind that when posting a code in the Community, It's way easier for everyone to read your code when you use the Markdown Cheatsheet.

As I can see, in the third question of your quiz you are asking the user to put The name of their favorite football team and The year of foundation

One of the main issues here is that, you are asking for 2 user inputs (details to be providen to the program by the user) with one prompt dialog. - name and the year

If you would like to leave your question as it is at the moment, you can code it like this..

let quiz3 = prompt('please enter the best football team in the world, both the name and the year they was created!!');
 if (quiz3 === 'legia 1916'){
     alert('correct');
    }
 else {  
      alert('wrong!!');
     }

Other way of coding it could be..

alert('please enter the best football team in the world, both the name and the year they was created!!');
let quiz3_Name = prompt(`Please enter the name of the football team.`);
let quiz3_Year = prompt(`Please enter the year of foundation.`);
 if (quiz3_Name === 'legia' && quiz3_Year === 1916){

     alert('correct');
    }
 else {  
      alert('wrong!!');
     }

Other main issue, is your if - statement

if (quiz3 === 'legia' && 1916)

This If statement will return true only when quiz3 is legia and 1916 at the same time. This is impossible due to the fact that legia and 1916 are completely different .

When you use the "&&" operator, the statement will return true only when both of the evaluations are true.

For example

let gender = prompt(`Please enter your gender`);
let age = prompt(`Please enter your age`);

if (gender == `boy` &&  age > 18 ) {
 console.log(`You could be a Male model`);
}

The if-statement will return True, only when age and gender evaluations return True.

Example for True input

  • gender = boy;
  • age = 20;

Example for False input

  • gender = boy;
  • age = 14;

I really hope I've helped you with your case! If you have more answers, I'll be glad to help!

Happy coding! :) Mino