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 Making Decisions in Your Code with Conditional Statements The Conditional Challenge Solution

Clare Yeadon
Clare Yeadon
5,553 Points

Working with multiple Possible answers

Hello,

I got hung up on how to treat my quiz question answers since they were a number, for example question one (please excuse my lack of creativity) “How many legs does a dog have?” The answer could be four or 4. I know using .toUpperCase would help with the multiple answers connected to string ‘four’ But how do I put it all together with the numerical 4?

Clare Yeadon
Clare Yeadon
5,553 Points

Oh maybe this is an avance topic and I should just stick to word answers, is this possible?

1 Answer

You could chain an if statement together to cover both that would look like this

const answer = (how ever you get the answer)
const loud = answer.toUpperCase();

if (answer === 4 || loud === "FOUR") {
      code to execute
}

This says if answer is equal to 4 execute the code if it is not does loud equal "FOUR" if it does execute the code if not skip the code.

Another way to write this and what I like to use is by using flags or something I can change to true if it is the right answer.

const answer = (how ever you get the answer)
const loud = answer.toUpperCase();
let isCorrectAnswer = false;

if (answer === 4 || loud === "FOUR") {
      isCorrectAnswer = true

      if (isCorrectAnswer) {
             code to execute
       }
}