DEV Community

Nkem
Nkem

Posted on • Updated on

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.

Top comments (9)

Collapse
 
sarveshprajapati profile image
Sarvesh Prajapati

Try to elaborate more in the blog.. That would make more sense...

BTW. recently I've also published my article about If-else and swicth..
You can check out here:
if else in JavaScript - Conditional Statements

Switch statement in JavaScript

Collapse
 
nkemdev profile image
Nkem

Thanks for the input. I will do do.

Collapse
 
andrewbaisden profile image
Andrew Baisden

Keep up the good progress!

Collapse
 
nkemdev profile image
Nkem

Thank you

Collapse
 
messimoraes profile image
Messi

Keep learning 👏👏👏

Collapse
 
codewithyaku profile image
CodeWithYaku

Great start 🎉

Collapse
 
nkemdev profile image
Nkem

Thank you.

Collapse
 
sunnydebjit profile image
Debjit Majumdar

Hello, which course are you following?

Collapse
 
nkemdev profile image
Nkem

I enrolled in the Scrimba JavaScript course.