Home > Enterprise >  How to assign a string to a variable using if else in javascript?
How to assign a string to a variable using if else in javascript?

Time:04-06

im trying to have my function use an if else statement to determine whether or not a hypothetical salary is good enough and print the result back to my HTML page. .image of my code

I feel like the code im using in my if else statement is good, but it seems to be getting skipped over and when I print the results on the HTML, the variable "amount" is not displayed, but "salary" is

CodePudding user response:

Remove let before amount in if else statements and the code will work as expected. The issue is, by using let again and again in if else statements, you're declaring amount variable again and again. Read about scope of let to learn more.

CodePudding user response:

You shouldn't use let from inside of if-else statements because the let variable is block scope with your code it means you are creating a new variable with string value not reassigning value for the first amount variable

  • Related