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 trialMark Reitz
692 Pointscan't get get anything
I started with this and am super frustrated. I can't even get past the first if - else scenario. What am I doing wrong?
var a = 10; var b = 20; var c = 30; var d = 40; var e = 50; var answerTrue = true; var answerFalse = false; var score = 0; var correctAnswers = 0;
var question1 = prompt("Is a > 20.....true or false"); if (question1.toUpperCase === "no") { alert("You are correct"); } else { alert("You are Wrong") }
1 Answer
andren
28,558 PointsThere are a couple of issues, mainly with the toUpperCase
method call:
- When calling a method you have to place a pair of parenthesis after its name, this is the case regardless of whether you are passing in any values to the method. So
question1.toUpperCase
should bequestion1.toUpperCase()
. - The
toUpperCase
method will convert the string you call it on to upper case, but after converting the string you compare it to a lowercase solution. Meaning that if "No" was entered as an answer the comparison would become "NO" === "no", which would be evaluated asfalse
since JavaScript is case-sensitive.
When converting the case of the answer you need to make sure the solution is written in the same case that the answer is converted to. So either you need to change your code to question1.toUpperCase() === "NO"
or you need to replace the toUpperCase
method with toLowerCase
like this: question1.toLowerCase() === "no"
.
Fixing that issue will make your code work, but I assume you want the "a" inside of your question prompt to be replaced with the actual value of the a
variable, rather than just printing out the literal letter "a" like you currently do. In that case you have to use string concatenation like this for example: prompt("Is " + a + " > 20.....true or false")
.