Dear all of you ,
I have solved the first project of Javascript related to the section Conditional Statements.
let userName = 'Alessio';
if (userName){
console.log('Hello, ' + userName + '!');
} else {
console.log('Hello!');
}
let userQuestion = 'What is the capital city of Italy?';
console.log(userQuestion);
randomNumber = Math.floor(Math.random()*8);
switch(randomNumber){
case 1:
console.log('It is certain');
break;
case 2:
console.log('It is decidedly so');
break;
case 3:
console.log('Reply hazy try again');
break;
case 4:
console.log('Cannot predict now');
break;
case 5:
console.log('Do not count on it');
break;
case 6:
console.log('My sources say no');
break;
case 7:
console.log('Outlook not so good');
break;
case 8:
console.log('Signs point to yes');
break;
default:
console.log('');
break;
}
The instructor uses the variable eightball to save the string of case statement. I haven’t used it. The result seems to be the same.
What do you think? Which is the difference in these two types of approach?
Thank you for your help
Best Regards
Alessio