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

whitneywilkerson
whitneywilkerson
3,762 Points

javascript basics: the conditional challenge getting 4 out of 5

Hi everyone, I hope you are all doing well and having a good weekend/ week (depending on where you are in the world!). I have been working through the conditionals quiz challenge and I'm doing pretty well. The only issue I seem to have is the number is not evaluated to a true statement and therefore is not getting counted.

here's my code: https://w.trhou.se/5oajvds13p

I hope that that works! it's my first time trying to share my code on here.

Here are a few things I tried: I first had "30" so I changed it to 30 so that they match exactly as the answer wouldn't be a string once entered in and therefore wouldn't be ===. Then I changed it from 30 to the word 'THIRTY' and entered that into the quiz as well, Finally, I deleted the .toUppercase() and left it as variable name = === 30. I am still getting some of the answers wrong in the quiz.

Any help would be appreciated.

Thanks!

3 Answers

Sorry, I goofed...

Here is your problem (I assume a copy-n-paste error, which trips me up ALL THE TIME!?! Ugh!?! LOL)

const questionFive = prompt("What is my name?");
if(questionOne.toUpperCase() === 'WHITNEY'){ //*****  Should be questionFive  *****
  correctAnswers += 1;
}

Errors like that are hard to spot (which is where a sh*tload of console.log statements can help!?!).

I hope that helps.

Stay safe and happy coding!

whitneywilkerson
whitneywilkerson
3,762 Points

Thanks. I figured it was a typo somewhere and I'd give it some time and return to it!

Hi Whitney!

I pasted this:

<!DOCTYPE html>
<html>
<body>

<main></main>

<script>
/* 
  1. Store correct answers
   - When quiz begins, no answers are correct
*/
let correctAnswers = 0;

// 2. Store the rank of a player

let playerRank;
// 3. Select the <main> HTML element
const main = document.querySelector('main');

/*
  4. Ask at least 5 questions
   - Store each answer in a variable
   - Keep track of the number of correct answers
*/
const questionOne = prompt(" What is my favorite color?");
if(questionOne.toUpperCase() === 'ORANGE'){
  correctAnswers += 1;
}
const questionTwo = prompt("How Old am I?");
if(questionTwo.toUpperCase() === 'THIRTY'){
  correctAnswers += 1;
}
const questionThree = prompt("What is my mother's madien name?");
if(questionThree.toUpperCase() === 'WILKERSON'){
  correctAnswers += 1;
}
const questionFour = prompt("What school will I be attending in April?");
if(questionFour.toUpperCase() === 'CODINGDOJO'){
  correctAnswers += 1;
}
const questionFive = prompt("What is my name?");
if(questionOne.toUpperCase() === 'WHITNEY'){
  correctAnswers += 1;
}


/*
  5. Rank player based on number of correct answers
   - 5 correct = Gold
   - 3-4 correct = Silver
   - 1-2 correct = Bronze
   - 0 correct = No crown
*/
if( correctAnswers === 5) {
  playerRank =  "Gold";
} else if(correctAnswers >= 3) {
  playerRank = "Silver";
}
else if( correctAnswers >= 1) {
  playerRank =  "Bronze"
}
else {
  playerRank= " Sorry no crown for you!"
}

// 6. Output results to the <main> element

main.innerHTML = `<h2> You got ${correctAnswers} our of 5 questions correct<h2><p> Crown earned:<strong>${playerRank}</strong></p>`;
</script>

</body>
</html>

Here:

https://www.w3schools.com/js/tryit.asp?filename=tryjs_array

Overwrite all the code in the left pane and then run it - worked for me!

If you have issues, add a boatload of console.log statements to see what's not working!

I hope that helps.

Stay safe and happy coding!?!

whitneywilkerson
whitneywilkerson
3,762 Points

Hi Peter,

Thanks for answering. Just for clarification, are you saying there is nothing wrong with my code? I copy and pasted it into VS code and ran it that way, it still comes back as only 4 out of 5 correct for me. I would send a screenshot, but it doesn't seem like I'm able to do so.

Also, feel free to hit me up and I'll test more or whatever...

Cheers! (keep at it - you'll get it!)

-Pete