Someone could explain me the difference between let
, var
, and const
?
I saw other coders that used var userName = ""
or in point 3 the hint suggests const userQuestion = 'blablabla'
//1
let userName = '';
//2
userName ? console.log(`Hello, ${userName}`) : console.log('Hello!');
//3
let userQuestion = 'Do I go in Amsterdam?';
//4
console.log(`The User asked: ${userQuestion}`);
//5
let randomNumber = Math.floor(Math.random() * 8);
//6
let eightBall = '';
switch (randomNumber) {
case 0:
eightBall = 'It is certain';
break;
case 1:
eightBall = 'It is decidedly so';
break;
case 2:
eightBall = 'Reply hazy try again';
break;
case 3:
eightBall = 'Cannot predict now';
break;
case 4:
eightBall = 'Do not count on it';
break;
case 5:
eightBall = 'My sources say no';
break;
case 6:
eightBall = 'Outlook not so good';
break;
case 7:
eightBall = 'Signs point to yes';
break;
}
//8
console.log(`The eight ball answered: ${eightBall}`);