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 trialAaron Retter
5,871 PointsDifficulty
I'm having a hard time figuring out how to answer 2 of the questions in this quiz. The first one is completing a switch statement and the other problem relates to writing a multiple if else statement function.
1 Answer
Stone Preston
42,016 Pointsto chain if statements together you need to use the else if keyword. you start the chain with and if, connect ifs together with and if else, and then end the chain with an else.
if (x == 1) {
} else if (x == 3) {
} else if (x == 4) {
} else {
}
switch statements generally look like this:
switch (someVariable) {
case 1:
some statement;
break;
case 2:
some statement;
break;
default:
some statement;
break;
}