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 trialIngrid Pettersson
9,916 PointsRegarding 'else if'-functions
In one of the questions after the video about 'else-if'-functions the following was asked:
"Consider the code below. What is the value of itemToBuy?
let itemToBuy = ''; const savings = 1000; if ( savings > 500 ) { itemToBuy = 'Computer'; } else if ( savings > 200 ) { itemToBuy = 'Phone'; } else if ( savings > 0 ) { itemToBuy = 'Dinner'; } else { itemToBuy = '...still saving...'; }
A. 'Phone' B. 'Dinner' C. '...still saving...'"
Based on what I've learned so far I think that because the first 'if'-condition is true only that code should run and the answer should then be 'Computer' which is not one of the options here. I tried to answer C just to answer something. It was wrong and I got the same explanation as my own to why it was wrong, but the correct answer wasn't told. Would be glad for some help! :)
1 Answer
Steven Parker
231,248 PointsThe question has 4 answer choices but you only show 3 here. Perhaps you need to scroll down your browser window to see the other choice.
Ingrid Pettersson
9,916 PointsIngrid Pettersson
9,916 PointsThanks for your reply Steven! I scrolled down and there was nothing but when I restarted the test there were 4 options and computer was one of them - and the correct one :)