I'm stuck on Sleep Debt Calculator Javascript lesson>Step 9

Here’s where I’m at. I’m studying web development. I’m on Section 3:Getting Started with Javascript>Functions>Sleep Debt Calculator>Step 9. The link below should take you there.


I’m stuck on Step 9. In this step, it’s asking for the creation of If/Else statements. I did it exactly as the lesson & the help video stated. Yet I keep getting an error message for the Else statement claiming a syntax error.

I’m going to enclose 2 screenshots so you can compare what I did, & what the video hostess did, which is identical.

  1. Screenshot Sleep Debt Calculator Step 9. (This will show you my project, with my code, & the error message on the right pane)

  2. Screenshot Sleep Debt Calculator Video 1332. (This is the screenshot of the video with the timestamp 13:32. Notice the Else syntax on is exactly the same as mine, yet the video hostess is not getting an error message on the right pane of her screen.)

What could I be missing? Is there a bug in the system?

By the way, how do I get notifications?

Hello @johnantonacci4655991. Should you have a semicolon after the condition in your if else statement? The syntax looks like this:

else if (condition) {

Unfortunately, that’s not the issue. I already did that, & I’m still getting the same error message.

Did you remove the semicolon? This is a simplified version of your code that I can see in the screenshot:

r = 8;
if (r > 8) 


else if (r == 8);




Which works when I remove the semicolon.

If that is not the problem, could you please post your full code. To format it, press this button:

and put the code between the back ticks:
Screen Shot 2020-05-02 at 14.06.13

const getSleepHours = day => 
  if (day === 'monday'){
    return 8;
  } else if (day === 'tuesday'){
    return 7;
  } else if (day === 'wednesday'){
    return 6; 
  } else if (day === 'thursday'){
    return 8;
  } else if (day === 'friday') {
    return 9; 
  } else if (day === 'saturday') {
    return 6;
  } else if (day === 'sunday') {
    return 8;
  } else {
    return unknown;

const getActualSleepHours = () => 
getSleepHours('monday') + getSleepHours('tuesday') + getSleepHours('wednesday') + 
getSleepHours('thursday') + getSleepHours('friday') + getSleepHours('saturday') + getSleepHours ('sunday'); 

const getIdealSleepHours = () => {
  const idealHours = 9;  
  return idealHours * 7;

const calculateSleepDebt = () => {
  const actualSleepHours = getActualSleepHours();
  const idealSleepHours = 

if (actualSleepHours === idealSleepHours) {
 console.log("You got the perfect amount of sleep")

else if (actualSleepHours > idealSleepHours) {
  console.log('Too much sleep')

else if (actualSleepHours < idealSleepHours) {
  console.log('Get more sleep')

else {
  console.log('Something went wrong, check your code!')

if (actualSleepHours < idealSleepHours) {
  console.log('You got ' + (idealSleepHours - actualSleepHours) + ' hour(s) less sleep than you needed this week. Get some rest.');

else if (actualSleepHours > idealSleepHours) {
  console.log('You got ' + (actualSleepHours - idealSleepHours) + ' hour(s) more sleep than you needed this week');

else if (actualSleepHours === idealSleepHours) {
  console.log('You got ' + (actualSleepHours === idealSleepHours) + 'you have just the right amount of sleep you need')


The if statement here:

uses variables outside of their scope. Consider looking at the code here:

Should you be closing the function?

Also, you don’t need the semicolon after the closing curly brace }.

I hope this helps!

Well, I keep getting error messages elsewhere. I’m over my head. I’m going to erase it, & start all over. I’ll watch the video & see how Galena handles the project. I’ll get back to you. Thank you anyway for your efforts to assist me, I appreciate it. :grinning:

1 Like

I completed the project. Thank you for your help.

1 Like