I'm wanting to print number + 1 in the console log but instead of adding the numbers together, it concatenates them. What am I doing wrong? For instance, if the user inputs 7, instead of getting 8, it will print 17.
let number = prompt('what is your favorite number')
if(number == 42){
console.log("Yay! That's my favorite too!")
} else if (number < 42){
console.log("Eh, that's OK but " + (1 + number) + " would have been better")
} else{
console.log("LAME. That number is too large!")
}
console.log()
If a user inputs a number less than 42, it should add 1 to the entered number and print that number. However, the current code is concatenating 1 to the number.
number*1, this is clearly a number operation so javascript will treat number as a number and not as a string.