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 trialThomas Palzkill
2,402 PointsOperators not adding to correct answer variable
As far as i can tell my code is set up (so far) similar to that in the solution video but when I preview correct ans is always equal to 1, regardless of correct answers.
var correctAns = 0; var weight = prompt("what is my weight?"); if (weight === '135') { correctAns +=1; } var meal = prompt("What is my favorite meal?"); if (meal.toUpperCase === "CHICKEN PARMESEAN") { correctAns +=1; } var weed = prompt ("I like weed?"); if (weed.toUpperCase === "yes") { correctAns +=1; } var home = prompt ("My homestate is Texas?"); if (home.toUpperCase === "yes") { correctAns +=1; } var game = prompt ("I like video games?"); if (game.toUpperCase === "yes") { correctAns +=1; } document.write("<p> You got " + correctAns + "answers correct<p>");
2 Answers
Steven Parker
231,275 PointsWhen you call a function or method, you must put parentheses after the name even if no arguments are being passed. Also, if you convert a string to upper case, it will only match a literal string that is also upper case.
Examples:
if (home.toUpperCase === "yes") // method not invoked and wrong case to match
if (home.toUpperCase() === "YES") // correct
Brian Foley
8,440 Pointsif (game.toUpperCase === "yes")
remember to add () after the .toUpperCase method