Help with iteration crashing code academy

edit : cudn’t get a tag to work

Currently dealing with the sleep debt project, and it wanted me to manually add each hour value from the days passed through the function as specified in the hint.
from coding in python I assumed I could do the same via iterating, so Im guessing my iteration at the bottom gets stuck in an infinite loop by the program. any one point out my mistakes?

totalHours = 0 // create variable to track total hours for later

//function which returns a value when you enter a day of the week
function hourSlept(day){

  day = day.toLowerCase();


    case "monday":

      return 8;

    case "tuesday":

      return 8;

    case "wednesday":

      return 8;

    case "thursday":

      return 8;

    case "friday":

      return 8;

    case "saturday":

      return 8;

    case "sunday":

      return 6



console.log(hourSlept("wednesday")) // me testing a day of the week 

// creating an array of days to iterate through which I can pass into the function
days = ["monday","tuesday","wednesday","thursday","friday","saturday","sunday"]

// the iteration that kills everything.
for(let i=0; i=6; i++){

  totalHours = totalHours + hourSlept(days[i]);

  console.log(totalHours); // just to track it


Thank-you for any help!

true, you wrote an infinity loop

you use assignment here:


which isn’t a good thing to do. Now JS will simple evaluate 6 as a truthy value.

How do i get this to work? sorry havent actually got as far as iteration in the course yet so am piecing together bits from google.

as you can see in documentation:

you could use a comparison operator.

1 Like

Thanks very much! worked a charm

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.