Skip to content

Instantly share code, notes, and snippets.

@zkwsk
Created October 19, 2017 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zkwsk/2da475090e6c924e2d565d548e9c2f81 to your computer and use it in GitHub Desktop.
Save zkwsk/2da475090e6c924e2d565d548e9c2f81 to your computer and use it in GitHub Desktop.
HYF JS-1 Session 2 - Lesson
//Control flow if staments
//IF ELSE
/*
let number = 1;
if(number >= 3) {
console.log('This number is greater or equal to 3');
} else if (number < 5 ){
console.log('This number is smaller than 2');
} else(number < 3) {
console.log('This number is exactly 2');
}*/
//Switch
/*
let number = 100;
switch(number){
case 2:
console.log('the number is 2');
break;
case 1:
console.log('the number is 1');
break;
default:
console.log('the number is not 1 or 2');
break;
}*/
//Loops
//While
/*
console.log(1)
console.log(2)
console.log(3)
console.log(4)*/
/*
let i = 1;
while(i > 0) {
//console.log(i);
i = i + 2;// i += 1// i = i + 1, i += 2, i+=3
}
console.log(i)
*/
//For
// let friends = ['Zaki','Rasmus','Solomon','Abdulla','Tala', 'Mohammad', 'Christopher'];
//Array.length = the length of the array so var arr = [1,2] arr.length = 2
//console.log('length of friends ' + friends.length)
/*
console.log( 'Hello '+ friends[0] + '!')
console.log('Hello '+ friends[1] + '!')
console.log('Hello '+ friends[2] + '!')
console.log('Hello '+ friends[3] + '!')*/
/*
for(let i = 0; i < friends.length; i ++ ) {
let friend = friends[i];
console.log(`Hello ${friend}!` );
}*/
// Functions
// Takes arguments
// Return a value
// function myFullName(firstname, lastname) {
// console.log(`${firstname} ${lastname}`);
// return true;
// }
// myFullName("Zaki", "Wasik");
// // Hello my name is [firstname] [lastname] and I am [age] old.
// myFullName2("Zaki", "Wasik", 33);
// // Hello my name is Zaki Wasik and I am 33 old.
// myFullNameFormal("Zaki", "Wasik", 33, true);
// // Hello my name is Wasik, Zaki and I am 33 old.
function myFullNameFormal(firstname, lastname, age, formal) {
if (formal) {
console.log(`Hello my name is ${lastname}, ${firstname} and I am ${age} old.`);
} else {
console.log(`Hello my name is ${firstname} ${lastname} and I am ${age} old.`);
}
}
myFullNameFormal("Zaki", "Wasik", 33, false);
// Hello my name is Wasik, Zaki and I am 33 old.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment