BASIC JS - NeverGiveUp143/JS GitHub Wiki
Sample First Function
function myFirstFunction() {
console.log('JS Function');
}
Output:
JS Function
Control Flow (if statements, loops) Sample Functions
function greeting() {
const hours = new Date().getHours();
let greeting;
if (hours < 12) {
greeting = "Good morning";
} else if (hours < 18) {
greeting = "Good afternoon";
} else {
greeting = "Good evening";
}
console.log(greeting)
}
const array = ['One-Piece','DragonBall-Z','Bleach','hunterXhunter','Naruto']
function arrayPrint() {
for (var i = 0; i < array.length; i++){
console.log(array[i]);
}
}
arrayPrint();
const carArray = ['Bugati', 'Lamborghini', 'Ferrai', 'Porsche']
function carArrayPrint() {
carArray.forEach(function (car) {
console.log(car);
})
}
carArrayPrint();
function EvenOrOdd(value) {
let number = value;
while (number % 2 === 0 && number > 0 ) {
console.log(number);
number = number / 2;
}
}
EvenOrOdd(20);
function doWhile(value) {
let number = value;
do {
console.log(number);
number = number / 2;
}while (number % 2 === 0 && number > 0 )
}
doWhile(20)