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 Booleans and Else If Review

Ingrid Pettersson
Ingrid Pettersson
9,916 Points

Regarding '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
Steven Parker
211,076 Points

The 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
Ingrid Pettersson
9,916 Points

Thanks 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 :)