Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics Making Decisions in Your Code with Conditional Statements The Conditional Challenge Solution

Clare Yeadon
Clare Yeadon
5,452 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,452 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
       }
}