‘16-‘17 General Discussion for Lesson 5.9


#1

Use this thread to discuss your questions and comments about how to run the lesson.


#2

Help! I can’t seem to figure this program out for the life of me. I’ve attached the code below. I can’t get it to function the correct way each time. Anyone have an idea of why my code is not executing properly?

var day = prompt(“Enter a day of the week.”);
var age = promptNum(“Enter your age.”);
write("Day is: " + day);
write("Age is: " + age);
if (age<18 && (!(day == “Saturday” || day == “Sunday”))) {
write(“Time for School!”);
} else if ((age>18) && (!(day == “Saturday” || day == “Sunday”))) {
write(“Time to go to work!”);
} else {
write(“Time to relax for the weekend!”);
}

Thanks in advance for the help!


#3

@nick.bahr

So, I think you probably have the problem when the age is 18. Check your conditionals. Neither one of them checks for when the age is 18 i.e. 18<18 is false and 18>18 is false. If you can answer the question - Where should I include 18? - then the fix should is simple.

Hope that helps!

Andrea


#4

Andrea,

Thank you for the help. I actually figured it out almost immediately after posting this. It’s been a hectic couple of weeks, thank goodness for a 3 day weekend coming up! Take care.

Nick