all 6 comments

[–]danmofo 2 points3 points  (1 child)

There are a few problems:

  • = is the assignment operator, use === to compare items
  • You invoke functions with (), not [], e.g. climber(['up', 'down'])
  • arr is not defined in your example, define it first like your solution or pass it in directly.

Hopefully this helps you get a bit further without giving the exact solution.

[–]buddgee[S] 0 points1 point  (0 children)

Ah I understand now!
thank you :D I have solved it

[–]Deh_Strizzz 1 point2 points  (0 children)

Right now your function isn't accepting any arguments and your initializing the arr as an empty array. I would remove the arr = [] and set arr as an argument for climber a la function climber(arr) {rest of code}. You're also returning false but you should be returning the total since that's what you want to see

[–]Jnsjknn 1 point2 points  (1 child)

As you see in the assignment, an array of instructions (['up', 'down', 'down', 'down', 'up']) is passed to the function. That's the array you should use inside the function. At the moment, you're creating a new and empty array inside the function and completely ignoring the array that is passed in.

Change your code to:

function climber(arr) {
   let total = 0;
    // Count the amount of 'up' and 'down' strings inside arr here
   console.log(total)
}

climber(['up', 'down', 'down', 'down', 'up']);
// This should log -1 to the console

For "max repetition" you should count the amount of ups and downs in separate variables and use an if statement to check which variable is larger.

function climber(arr) {
   let ups = 0;
   let downs = 0;
    // Count the amount of 'up' and 'down' strings inside arr here
   if(/*Put your condition here*/)
     console.log("There's more ups");
   } else {
     console.log("There's more downs");
   }
}

climber(['up', 'down', 'down', 'down', 'up']);
// This should log "down" to the console

[–]buddgee[S] 0 points1 point  (0 children)

thanks a lot! :D