There are endless possibilities if one would try to do great to achieve a particular goal and put tons of trial and error to the test.
We can use a ternary operator to perform this same functionality:
isNightTime ? console.log('Turn on the lights!') : console.log('Turn off the lights!');
In the example above:
- The condition,
isNightTime
, is provided before the?
. - Two expressions follow the
?
and are separated by a colon:
. - If the condition evaluates to
true
, the first expression executes. - If the condition evaluates to
false
, the second expression executes.
Code Snippets
let userName = 'Teddy';
if(userName) {
console.log('Hello There!');
}
let userQuestion = 'Why is the sky blue?';
console.log(`${userName}, I have a question for you. ${userQuestion}`);
let randomNumber = Math.floor(Math.random() * 8);
// console.log(randomNumber);
let eightBall = '';
eightBall = randomNumber;
switch (eightBall) {
case 8:
console.log('It is certain');
break;
case 7:
console.log('It is decidedly so');
break;
case 6:
console.log('Reply hazy try again');
break;
case 5:
console.log('Cannot predict now');
break;
case 4:
console.log('Do not count on it');
break;
case 3:
console.log('My sources say no');
break;
case 2:
console.log('Outlook not so good');
break;
case 1:
console.log('Signs point to yes');
break;
default:
console.log(eightBall);
break;
}
console.log(eightBall);
a11y myths
Accessibility is only about adding alternative text to images
In fact, missing alternative text for images is one of the biggest accessibility issues. But besides this, there are many things to be considered while making accessible website - headline structure, functional controls, color contrast and much more.
Top comments (0)