// let's assume this function will return a random number of 1 to 6
let diceNumber = randomDiceNumber();
if(diceNumber % 2 == 0 && diceNumber == 4){
lose()
}
else if(diceNumber % 2 == 0 && (diceNumber == 1 || diceNumber == 6)){
win()
}
else if(diceNumber % 2 == 1 && diceNumber == 3){
win()
}
else if(diceNumber % 2 == 1){
lose()
}
var names = "reemo";
let age = 123;
const isMale = true;
// <declare_words> <declare_variables_name> = <data_values>
let names = "reemo";
const age = 10;
let names = "reemo";
console.log(names) // reemo
names = "tom"
console.log(names) // tom
const names = "reemo";
console.log(names) // reemo
names = "tom" // Cannot assign to 'names' because it is a constant.
console.log(names) // error: Uncaught TypeError: Assignment to constant variable.
let num = 100; // type: number
let stringNum = "100" // type: string
console.log( num == stringNum ) // Weak compare: true
console.log( num === stringNum ) // Strong compare: false
10 > 6 // true
5 < 89 // true
10 > 10 // false, why? Since 10 is not bigger than 10, is equal to 10
10 >= 10 // true
// Only the conditions between the () are true, the under code will run
if(true){
console.log("I will run yeah 😀")
}
if(false){
console.log("I will NOT run oh no 😥")
}
let nums = 100;
if(nums > 10){
nums += 23 // this code will run since 100 > 10 is true
}
console.log(nums) // 123
let nums = 5;
if(nums > 10){
nums += 23 // this code will NOT run since 5 > 10 is false
}
console.log(nums) // 5
// If the conditions in `if` is false, it will run the else code sections
if(false){
console.log("I will NOT run oh no 😥")
}
else{
console.log("I will run yeah 😀")
}
let nums = 20;
if(nums > 10){
nums += 23 // if the nums > 10 is true, this line will run
}
else{
nums -= 10 // if the nums > 10 is false, this line will run
}
console.log(nums) // 43
let nums = 5;
if(nums > 10){
nums += 23 // if the nums > 10 is true, this line will run
}
else{
nums -= 10 // if the nums > 10 is false, this line will run
}
console.log(nums) // -5
if(true){
console.log("I will run yeah 😀")
}
console.log("I will run no matter if() is true or false")
if(false){
console.log("I will run yeah 😀")
}
else{
console.log("I will run But only if() is false")
}
let nums = 50;
if(nums == 10){
console.log("I am a 10")
}
else if(nums == 20){
console.log("I am a 20")
}
else{
console.log("nope") // This line will printed
}
// "nope"
let nums = 10;
if(nums == 10){
console.log("I am a 10") // This line will printed
}
else if(nums == 20){
console.log("I am a 20")
}
else{
console.log("nope")
}
// "I am a 10"
let nums = 20;
if(nums == 10){
console.log("I am a 10")
}
else if(nums == 20){
console.log("I am a 20") // This line will printed
}
else{
console.log("nope")
}
// "I am a 20"
function myFunctionName(){
// Stuff to do when this function is called.
console.log("Hello mate.")
}
myFunctionName() // calling the function
function greetings(names){
// Stuff to do when this function is called.
console.log("Hello " + names)
}
greetings("peter") // Hello peter
greetings("tom") // Hello tom
function greetings(names, ages){
// Stuff to do when this function is called.
console.log("Hello " + names)
console.log("Are you the age of " + ages + " ?")
}
greetings("peter", 18) // Hello peter / Are you the age of 18 ?
greetings("tom", 33) // Hello tom / Are you the age of 33 ?
function returnSentences(names){
let sentences = "Hello " + names;
return sentences
}
let myNameSentences = returnSentences("peter"); //myNameSentences = "Hello peter"
console.log(myNameSentences); // "Hello peter"
console.log(returnSentences("tom")); // "Hello tom"