This is not an issue. The problem is with your code. You defined your sum variable outside the function, so it's global. It needs to be defined inside your function so it's a local variable.
I hadn't realized how awesome it is to be able to review other solutions until this challenge. I knew there was a better way than my initial solution, but it's so great to be able to review all of them and see some of the ideal ways of going about things.
This is how I did it but I used a ternary operator
Oh I never saw that one, thanks you for reply !
Hi! This is a shorter way of accessing the
.charAt()
method on a string. Take a look at the docs here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#character_accessHi! Beginner here, I thought [] was for the array only. Why, can we use [] for the string "name" here? Sorry for my bad english.
This is more or less how I did mine. The only difference is that I used string interpolation instead.
This comment is hidden because it contains spoiler information about the solution
In general a good practice is to avoid unnecessary code, but sometimes it's better to write more for readability.
Isn't also a best practice not to have multiple return statements when not necessary?
It's not a good practice to put else statement after return.
.
This is not an issue. The problem is with your code. You defined your
sum
variable outside the function, so it's global. It needs to be defined inside your function so it's a local variable.I hadn't realized how awesome it is to be able to review other solutions until this challenge. I knew there was a better way than my initial solution, but it's so great to be able to review all of them and see some of the ideal ways of going about things.
This comment is hidden because it contains spoiler information about the solution