If I input this in the console it outputs correct result:
'99' - '99'.slice(1)
=> 90
But when I do this in a loop, it throws error, why?
let len = 4;
let nines = '9';
let sum = 0;
for (let i = 1; i < len 1; i ) {
sum = i * (nines - nines.slice(1));
nines = 9;
}
Uncaught TypeError: nines.slice is not a function
at <anonymous>:5:28
CodePudding user response:
i think it's a typo
nines = 9;
should be
nines = 9;
CodePudding user response:
nines = 9
sets nines
to 9
. Did you mean nines = '9'
CodePudding user response:
It was a typo, should be = 9. I didn't notice it as my attention was focused on the error message which pointed at slice.