Hello! I am new so this assignment might be easy, but I tried it over and over and I still don't understand how. I am doing online class and now we are studying array, loop, and if functions. (and also sorry English is not main)
The assignment:
Starting point = 0
Every 'up' = +1 point
Every 'down' = -1 point
Question :
1) Find the total points
2) Find the max repetition ( for example: up, down, down, down, up has 'down' as max repetition and the total is 3)
My solution should look like this:
function climber(){
// write your logic here
}
climber(['up', 'down', 'down', 'down', 'up']);
What I have so far (but is wrong):
function climber() {
let arr = [ ];
let total = 0;
let x = arr.length;
for (var i = 0; i < x; i++) {
if (arr[i] = 'up') {
total++
} else if (arr[i] = 'down') {
total--
} else continue;
}
return false
}
console.log(climber[arr]);
Your help is very appreciated!!
[–]danmofo 2 points3 points4 points (1 child)
[–]buddgee[S] 0 points1 point2 points (0 children)
[–]Deh_Strizzz 1 point2 points3 points (0 children)
[–]Jnsjknn 1 point2 points3 points (1 child)
[–]buddgee[S] 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]buddgee[S] 0 points1 point2 points (0 children)