Day 3 of 100 days of Code

nkemdev

Nkem

Posted on February 18, 2022

Day 3 of 100 days of Code

Blackjack game app learning javascript

Today I learnt the use of the conditional if/else if statements and the query selector in JavaScript and created a blackjack app. Blackjack is a game that you win when your card summation is nearer or equals to 21. 21 is the golden summation, but if there isn’t anyone in the game that has the number, the nearest number to 21 wins the game.
Conditional statements control behavior and determine whether or not pieces of code can be executed following an instruction. The types of conditional statements are:
• The ‘if’ statement
• ‘Else if’ statement
• ‘ else’ statement

The if statement is where if a condition is true, the blocks of code/statement will be executed. The else if statement is when the first condition is false then this will be executed. Then the else statement is where if all the statements preceding this statement are false then it will be executed.

Example

let firstNumber = 6
let secondNumber =13
let sum = firstNumber + secondNumber
if (sum < 21) {
console.log(“ You could be the winner”)
}

Enter fullscreen mode Exit fullscreen mode

Else if example


if (sum < 21) {
console.log(“ You could be the winner”)
}
else if ( sum ===21) {
console.log(“ Congratulations you have won the blackjack game” )
}

Enter fullscreen mode Exit fullscreen mode

Else example

f (sum < 21) {
console.log(“ You could be the winner”)
}
else if ( sum ===21) {
console.log(“ Congratulations you have won the blackjack game” )
}
else{
console.log (“ Sorry better luck next time”)
}

Enter fullscreen mode Exit fullscreen mode

Other two things I also learnt were the "==" and the "===".
The difference between them.
Example
5 =='5'
This will return true as it sees it as being similar irrespective of the data type difference. Hence you would say. It is not strict in differentiating.
5==='5'
This will return false as there are two different datatypes even though they look similar in view. The first is number five while the second is a string data type.

💖 💪 🙅 🚩
nkemdev
Nkem

Posted on February 18, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related