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 trialWANJYUN WANG
8,539 Pointsresult of my quiz will always be 0
Hi,guys I almost follow exactly the same of the example ans,but no matter how many correct ans I type,the result will always come back 0correct I feel like maybe I lack the parseInt?not sure,but I think the questions are no numbers involved,so I don't need one? just like the example ans.
//quiz start var correct=0;
//question var visitor1=prompt('who lead goverment?'); if(visitor1.toUpperCase==='PRESIDENT'){ correct+=1; }
var visitor2=prompt('what thing can shoot bullets?'); if(visitor2.toUpperCase==='GUN'){ correct+=1; }
var visitor3=prompt('usually people pet a dog or?'); if(visitor3.toUpperCase==='CAT'){ correct+=1; }
var visitor4=prompt('what do asain usually eat?'); if(visitor4.toUpperCase==='RICE'){ correct+=1; }
var visitor5=prompt('which race is the most wealthy one?'); if(visitor5.toUpperCase==='WESTERN'){ correct+=1; }
//results document.write('<p>you have got '+correct+' answers right</p>');
//ranking the results if (correct===5){ document.write('<p>You have eanred a gold crown</p>'); }else if(correct >=3 ){ document.write('<p>You have eanred a sliver crown</p>'); }else if (correct >=1 ){ document.write('<p>You have eanred a bronze crown</p>'); }else { document.write('<p>You fkin idiot!</p>'); }
3 Answers
Jon Mirow
9,864 PointsHi there, code's all good, you just need to add the brackets () to the .toUpperCase method calls ( remember you're calling a method, not accessing a property).
Other than that, good job! Maybe some user friendlier output ;)
WANJYUN WANG
8,539 PointsHi,Jon Mirow Thanks for reply, Yes it is the (),but that leads to another question if I end up with didn't put() in them which will become like visitor2.toUpperCase==='GUN' but in this case, even I put the 'GUN'in uppercase myself when I run the code in real the result would still come false,how come?
Jon Mirow
9,864 PointsAh because when you type
visitor2.toUpperCase
Javascript goes off to look for a property inside visitor2 called toUpperCase. what it finds is the function toUpperCase, so it passes that back, which results in something similar to this comparison being made
function toUpperCase === "GUN"
Which returns false.
WANJYUN WANG
8,539 PointsGreat! that's really helpful thanks for the effort Jon cheers