reorganizing some more
This commit is contained in:
+11
@@ -0,0 +1,11 @@
|
||||
let bool1 = false;
|
||||
let bool2 = true;
|
||||
console.log(typeof bool1)
|
||||
|
||||
let str1 = "JavaScript is fun!";
|
||||
let str2 = "JavaScript is fun!";
|
||||
console.log("These two strings are the same:", str1 === str2);
|
||||
|
||||
let sym1 = Symbol("JavaScript is fun!");
|
||||
let sym2 = Symbol("JavaScript is fun!");
|
||||
console.log("These two Symbols are the same:", sym1 === sym2);
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
// let nr1 = 2;
|
||||
// let nr2 = "2";
|
||||
// console.log(nr1 * nr2);
|
||||
|
||||
// let nr1 = 2;
|
||||
// let nr2 = "2";
|
||||
// console.log(nr1 + nr2);
|
||||
|
||||
// let nrToStr = 6;
|
||||
// nrToStr = String(nrToStr);
|
||||
// console.log(nrToStr, typeof nrToStr);
|
||||
|
||||
// let strToNr = "12";
|
||||
// strToNr = Number(strToNr);
|
||||
// console.log(strToNr, typeof strToNr);
|
||||
|
||||
// let strToBool = "any string will return true";
|
||||
// strToBool = Boolean(strToBool);
|
||||
// console.log(strToBool, typeof strToBool);
|
||||
|
||||
// let nullToNr = null;
|
||||
// nullToNr = Number(nullToNr);
|
||||
// console.log("null", nullToNr, typeof nullToNr);
|
||||
|
||||
// let strToNr = "";
|
||||
// strToNr = Number(strToNr);
|
||||
// console.log("empty string", strToNr, typeof strToNr);
|
||||
|
||||
// let strToNr2 = "hello";
|
||||
// strToNr2 = Number(strToNr2);
|
||||
// console.log(strToNr2, typeof strToNr2);
|
||||
|
||||
// let strToBool = "";
|
||||
// strToBool = Boolean(strToBool);
|
||||
// console.log(strToBool, typeof strToBool);
|
||||
|
||||
// let strToBool2 = "false";
|
||||
// strToBool2 = Boolean(strToBool2);
|
||||
// console.log(strToBool2, typeof strToBool2);
|
||||
|
||||
// let nr1 = 2;
|
||||
// let nr2 = "2";
|
||||
// console.log(nr1 + Number(nr2));
|
||||
@@ -1,184 +0,0 @@
|
||||
// let firstname = "Maria";
|
||||
// firstname = "Jacky";
|
||||
|
||||
// let nr1 = 12;
|
||||
// var nr2 = 8;
|
||||
// const pi = 3.14159;
|
||||
|
||||
// throws a TypeError
|
||||
// const someConstant = 3;
|
||||
// someConstant = 4;
|
||||
|
||||
// let singleString = 'Hi there!';
|
||||
// let doubleString = "How are you?";
|
||||
|
||||
// let language = "JavaScript";
|
||||
// let message = `Let's learn ${language}`;
|
||||
// console.log(message);
|
||||
|
||||
// let intNr = 1;
|
||||
// let decNr = 1.5;
|
||||
// let expNr = 1.4e15;
|
||||
|
||||
// let bigNr = 90071992547409920n;
|
||||
// typeError
|
||||
// let result = bigNr + intNr;
|
||||
|
||||
// let bool1 = false;
|
||||
// let bool2 = true;
|
||||
// console.log(typeof bool1)
|
||||
|
||||
// let str1 = "JavaScript is fun!";
|
||||
// let str2 = "JavaScript is fun!";
|
||||
// console.log("These two strings are the same:", str1 === str2);
|
||||
|
||||
// let sym1 = Symbol("JavaScript is fun!");
|
||||
// let sym2 = Symbol("JavaScript is fun!");
|
||||
// console.log("These two Symbols are the same:", sym1 === sym2);
|
||||
|
||||
// let unassigned;
|
||||
// console.log(unassigned);
|
||||
|
||||
// let terribleThingToDo = undefined;
|
||||
// let lastname;
|
||||
// console.log("Same undefined:", lastname === terribleThingToDo);
|
||||
|
||||
// let betterOption = null;
|
||||
// console.log("Same null:", lastname === betterOption);
|
||||
|
||||
// let empty = null;
|
||||
|
||||
// let nr1 = 2;
|
||||
// let nr2 = "2";
|
||||
// console.log(nr1 * nr2);
|
||||
|
||||
// let nr1 = 2;
|
||||
// let nr2 = "2";
|
||||
// console.log(nr1 + nr2);
|
||||
|
||||
// let nrToStr = 6;
|
||||
// nrToStr = String(nrToStr);
|
||||
// console.log(nrToStr, typeof nrToStr);
|
||||
|
||||
// let strToNr = "12";
|
||||
// strToNr = Number(strToNr);
|
||||
// console.log(strToNr, typeof strToNr);
|
||||
|
||||
// let strToBool = "any string will return true";
|
||||
// strToBool = Boolean(strToBool);
|
||||
// console.log(strToBool, typeof strToBool);
|
||||
|
||||
// let nullToNr = null;
|
||||
// nullToNr = Number(nullToNr);
|
||||
// console.log("null", nullToNr, typeof nullToNr);
|
||||
|
||||
// let strToNr = "";
|
||||
// strToNr = Number(strToNr);
|
||||
// console.log("empty string", strToNr, typeof strToNr);
|
||||
|
||||
// let strToNr2 = "hello";
|
||||
// strToNr2 = Number(strToNr2);
|
||||
// console.log(strToNr2, typeof strToNr2);
|
||||
|
||||
// let strToBool = "";
|
||||
// strToBool = Boolean(strToBool);
|
||||
// console.log(strToBool, typeof strToBool);
|
||||
|
||||
// let strToBool2 = "false";
|
||||
// strToBool2 = Boolean(strToBool2);
|
||||
// console.log(strToBool2, typeof strToBool2);
|
||||
|
||||
// let nr1 = 2;
|
||||
// let nr2 = "2";
|
||||
// console.log(nr1 + Number(nr2));
|
||||
|
||||
// let str = "Hello, what's your name? Is it \"Mike\"?";
|
||||
// console.log(str);
|
||||
// let str2 = 'Hello, what\'s your name? Is it "Mike"?';
|
||||
// console.log(str2);
|
||||
|
||||
// let str3 = "New \nline."
|
||||
// let str4 = "I'm containing a backslash: \\!";
|
||||
// console.log(str3);
|
||||
// console.log(str4);
|
||||
|
||||
// let str = "Hello";
|
||||
// let nr = 7;
|
||||
// let bigNr = 12345678901234n;
|
||||
// let bool = true;
|
||||
// let sym = Symbol("unique");
|
||||
// let undef = undefined;
|
||||
// let unknown = null;
|
||||
|
||||
// console.log("str", typeof str);
|
||||
// console.log("nr", typeof nr);
|
||||
// console.log("bigNr", typeof bigNr);
|
||||
// console.log("bool", typeof bool);
|
||||
// console.log("sym", typeof sym);
|
||||
// console.log("undef", typeof undef);
|
||||
// console.log("unknown", typeof unknown);
|
||||
|
||||
// let nr1 = 12;
|
||||
// let nr2 = 14;
|
||||
// let str1 = "Hello ";
|
||||
// let str2 = "addition";
|
||||
// let result1 = nr1 + nr2;
|
||||
// let result2 = str1 + str2;
|
||||
// console.log(result1, result2);
|
||||
|
||||
// let nr1 = 20;
|
||||
// let nr2 = 4;
|
||||
// let str1 = "Hi ";
|
||||
// let nr3 = 3;
|
||||
// let result1 = nr1 - nr2;
|
||||
// let result2 = str1 - nr3;
|
||||
// console.log(result1, result2);
|
||||
|
||||
// let nr1 = 15;
|
||||
// let nr2 = 10;
|
||||
// let str1 = "Hi";
|
||||
// let nr3 = 3;
|
||||
// let result1 = nr1 * nr2;
|
||||
// let result2 = str1 * nr3;
|
||||
// console.log(result1, result2);
|
||||
|
||||
// let nr1 = 30;
|
||||
// let nr2 = 5;
|
||||
// let result1 = nr1 / nr2;
|
||||
// console.log(result1);
|
||||
|
||||
// let nr1 = 2;
|
||||
// let nr2 = 3;
|
||||
// let result1 = nr1 ** nr2;
|
||||
// console.log(result1);
|
||||
|
||||
// let nr1 = 10;
|
||||
// let nr2 = 3;
|
||||
// let result1 = nr1 % nr2;
|
||||
// console.log(`${nr1} % ${nr2} = ${result1}`);
|
||||
|
||||
// let nr3 = 8;
|
||||
// let nr4 = 2;
|
||||
// let result2 = nr3 % nr4;
|
||||
// console.log(`${nr3} % ${nr4} = ${result2}`);
|
||||
|
||||
// let nr5 = 15;
|
||||
// let nr6 = 4;
|
||||
// let result3 = nr5 % nr6;
|
||||
// console.log(`${nr5} % ${nr6} = ${result3}`);
|
||||
|
||||
// let nr = 4;
|
||||
// nr++;
|
||||
// console.log(nr);
|
||||
|
||||
// let nr = 2;
|
||||
// console.log(nr++);
|
||||
// console.log(nr);
|
||||
|
||||
// let nr = 2;
|
||||
// console.log(++nr);
|
||||
|
||||
let nr1 = 4;
|
||||
let nr2 = 5;
|
||||
let nr3 = 2;
|
||||
console.log(nr1++ + ++nr2 * nr3++);
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
let str = "Hello, what's your name? Is it \"Mike\"?";
|
||||
console.log(str);
|
||||
let str2 = 'Hello, what\'s your name? Is it "Mike"?';
|
||||
console.log(str2);
|
||||
|
||||
let str3 = "New \nline."
|
||||
let str4 = "I'm containing a backslash: \\!";
|
||||
console.log(str3);
|
||||
console.log(str4);
|
||||
|
||||
let str = "Hello";
|
||||
let nr = 7;
|
||||
let bigNr = 12345678901234n;
|
||||
let bool = true;
|
||||
let sym = Symbol("unique");
|
||||
let undef = undefined;
|
||||
let unknown = null;
|
||||
|
||||
console.log("str", typeof str);
|
||||
console.log("nr", typeof nr);
|
||||
console.log("bigNr", typeof bigNr);
|
||||
console.log("bool", typeof bool);
|
||||
console.log("sym", typeof sym);
|
||||
console.log("undef", typeof undef);
|
||||
console.log("unknown", typeof unknown);
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
// let nr1 = 12;
|
||||
// let nr2 = 14;
|
||||
// let str1 = "Hello ";
|
||||
// let str2 = "addition";
|
||||
// let result1 = nr1 + nr2;
|
||||
// let result2 = str1 + str2;
|
||||
// console.log(result1, result2);
|
||||
|
||||
// let nr1 = 20;
|
||||
// let nr2 = 4;
|
||||
// let str1 = "Hi ";
|
||||
// let nr3 = 3;
|
||||
// let result1 = nr1 - nr2;
|
||||
// let result2 = str1 - nr3;
|
||||
// console.log(result1, result2);
|
||||
|
||||
// let nr1 = 15;
|
||||
// let nr2 = 10;
|
||||
// let str1 = "Hi";
|
||||
// let nr3 = 3;
|
||||
// let result1 = nr1 * nr2;
|
||||
// let result2 = str1 * nr3;
|
||||
// console.log(result1, result2);
|
||||
|
||||
// let nr1 = 30;
|
||||
// let nr2 = 5;
|
||||
// let result1 = nr1 / nr2;
|
||||
// console.log(result1);
|
||||
|
||||
// let nr1 = 2;
|
||||
// let nr2 = 3;
|
||||
// let result1 = nr1 ** nr2;
|
||||
// console.log(result1);
|
||||
|
||||
// let nr1 = 10;
|
||||
// let nr2 = 3;
|
||||
// let result1 = nr1 % nr2;
|
||||
// console.log(`${nr1} % ${nr2} = ${result1}`);
|
||||
|
||||
// let nr3 = 8;
|
||||
// let nr4 = 2;
|
||||
// let result2 = nr3 % nr4;
|
||||
// console.log(`${nr3} % ${nr4} = ${result2}`);
|
||||
|
||||
// let nr5 = 15;
|
||||
// let nr6 = 4;
|
||||
// let result3 = nr5 % nr6;
|
||||
// console.log(`${nr5} % ${nr6} = ${result3}`);
|
||||
|
||||
// let nr = 4;
|
||||
// nr++;
|
||||
// console.log(nr);
|
||||
|
||||
// let nr = 2;
|
||||
// console.log(nr++);
|
||||
// console.log(nr);
|
||||
|
||||
// let nr = 2;
|
||||
// console.log(++nr);
|
||||
|
||||
let nr1 = 4;
|
||||
let nr2 = 5;
|
||||
let nr3 = 2;
|
||||
console.log(nr1++ + ++nr2 * nr3++);
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
let unassigned;
|
||||
console.log(unassigned);
|
||||
|
||||
let terribleThingToDo = undefined;
|
||||
let lastname;
|
||||
console.log("Same undefined:", lastname === terribleThingToDo);
|
||||
|
||||
let betterOption = null;
|
||||
console.log("Same null:", lastname === betterOption);
|
||||
|
||||
let empty = null;
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
let firstname = "Maria";
|
||||
firstname = "Jacky";
|
||||
|
||||
let nr1 = 12;
|
||||
var nr2 = 8;
|
||||
const pi = 3.14159;
|
||||
|
||||
// throws a TypeError
|
||||
const someConstant = 3;
|
||||
someConstant = 4;
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
let intNr = 1;
|
||||
let decNr = 1.5;
|
||||
let expNr = 1.4e15;
|
||||
|
||||
let bigNr = 90071992547409920n;
|
||||
// typeError
|
||||
let result = bigNr + intNr;
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
let singleString = 'Hi there!';
|
||||
let doubleString = "How are you?";
|
||||
|
||||
let language = "JavaScript";
|
||||
let message = `Let's learn ${language}`;
|
||||
console.log(message);
|
||||
Executable
+100
@@ -0,0 +1,100 @@
|
||||
arr1 = new Array("purple", "green", "yellow");
|
||||
arr2 = ["black", "orange", "pink"];
|
||||
|
||||
arr3 = new Array(10);
|
||||
arr4 = [10];
|
||||
|
||||
console.log(arr3);
|
||||
console.log(arr4);
|
||||
|
||||
cars = ["Toyota", "Renault", "Volkswagen"];
|
||||
console.log(cars[0]);
|
||||
console.log(cars[1]);
|
||||
console.log(cars[2]);
|
||||
console.log(cars[3]);
|
||||
console.log(cars[-1]);
|
||||
|
||||
cars[0] = "Tesla";
|
||||
console.log(cars[0]);
|
||||
|
||||
cars[3] = "Kia";
|
||||
cars[-1] = "Fiat";
|
||||
console.log(cars[3]);
|
||||
console.log(cars[-1]);
|
||||
|
||||
colors = ["black", "orange", "pink"]
|
||||
booleans = [true, false, false, true];
|
||||
emptyArray = [];
|
||||
|
||||
console.log("Length of colors:", colors.length);
|
||||
console.log("Length of booleans:", booleans.length);
|
||||
console.log("Length of emtpy array:", emptyArray.length);
|
||||
|
||||
lastElement = colors[colors.length - 1];
|
||||
console.log(lastElement);
|
||||
|
||||
numbers = [12, 24, 36];
|
||||
numbers[-1] = 0;
|
||||
numbers[5] = 48;
|
||||
console.log(numbers.length);
|
||||
|
||||
console.log("numbers", numbers);
|
||||
|
||||
favoriteFruits = ["grapefruit", "orange", "lemon"];
|
||||
favoriteFruits.push("tangerine");
|
||||
|
||||
let lengthOfFavoriteFruits = favoriteFruits.push("lime");
|
||||
console.log(lengthOfFavoriteFruits);
|
||||
console.log(favoriteFruits);
|
||||
|
||||
let arrOfShapes = ["circle", "triangle", "rectangle", "pentagon"];
|
||||
arrOfShapes.splice(2, 0, "square", "trapezoid");
|
||||
console.log(arrOfShapes);
|
||||
|
||||
let arr5 = [1, 2, 3];
|
||||
let arr6 = [4, 5, 6];
|
||||
let arr7 = arr5.concat(arr6);
|
||||
console.log(arr7);
|
||||
|
||||
let arr8 = arr7.concat(7, 8, 9);
|
||||
console.log(arr8);
|
||||
|
||||
arr8.pop();
|
||||
console.log(arr8);
|
||||
|
||||
arr8.shift();
|
||||
console.log(arr8);
|
||||
|
||||
arr8.splice(1, 3);
|
||||
console.log(arr8);
|
||||
|
||||
delete arr8[0];
|
||||
console.log(arr8);
|
||||
|
||||
let findValue = arr8.find(() => e === 6);
|
||||
let findValue2 = arr8.find(() => e === 8);
|
||||
console.log(findValue, findValue2);
|
||||
|
||||
let findIndex = arr8.indexOf(6);
|
||||
let findIndex2 = arr8.indexOf(10);
|
||||
let findIndex3 = arr8.indexOf(6, 2);
|
||||
console.log(findIndex, findIndex2, findIndex3);
|
||||
|
||||
let animals = ["dog", "horse", "cat", "platypus", "dog"]
|
||||
let lastDog = animals.lastIndexOf("dog");
|
||||
console.log(lastDog);
|
||||
|
||||
|
||||
let names = ["James", "Alicia", "Fatiha", "Maria", "Bert"];
|
||||
names.sort();
|
||||
|
||||
let ages = [18, 72, 33, 56, 40];
|
||||
ages.sort();
|
||||
|
||||
console.log(names);
|
||||
console.log(ages);
|
||||
|
||||
names.reverse();
|
||||
console.log(names);
|
||||
|
||||
console.log(typeof arr1);
|
||||
@@ -1,104 +1,3 @@
|
||||
arr1 = new Array("purple", "green", "yellow");
|
||||
arr2 = ["black", "orange", "pink"];
|
||||
|
||||
arr3 = new Array(10);
|
||||
arr4 = [10];
|
||||
|
||||
console.log(arr3);
|
||||
console.log(arr4);
|
||||
|
||||
cars = ["Toyota", "Renault", "Volkswagen"];
|
||||
console.log(cars[0]);
|
||||
console.log(cars[1]);
|
||||
console.log(cars[2]);
|
||||
console.log(cars[3]);
|
||||
console.log(cars[-1]);
|
||||
|
||||
cars[0] = "Tesla";
|
||||
console.log(cars[0]);
|
||||
|
||||
cars[3] = "Kia";
|
||||
cars[-1] = "Fiat";
|
||||
console.log(cars[3]);
|
||||
console.log(cars[-1]);
|
||||
|
||||
colors = ["black", "orange", "pink"]
|
||||
booleans = [true, false, false, true];
|
||||
emptyArray = [];
|
||||
|
||||
console.log("Length of colors:", colors.length);
|
||||
console.log("Length of booleans:", booleans.length);
|
||||
console.log("Length of emtpy array:", emptyArray.length);
|
||||
|
||||
lastElement = colors[colors.length - 1];
|
||||
console.log(lastElement);
|
||||
|
||||
numbers = [12, 24, 36];
|
||||
numbers[-1] = 0;
|
||||
numbers[5] = 48;
|
||||
console.log(numbers.length);
|
||||
|
||||
console.log("numbers", numbers);
|
||||
|
||||
favoriteFruits = ["grapefruit", "orange", "lemon"];
|
||||
favoriteFruits.push("tangerine");
|
||||
|
||||
let lengthOfFavoriteFruits = favoriteFruits.push("lime");
|
||||
console.log(lengthOfFavoriteFruits);
|
||||
console.log(favoriteFruits);
|
||||
|
||||
let arrOfShapes = ["circle", "triangle", "rectangle", "pentagon"];
|
||||
arrOfShapes.splice(2, 0, "square", "trapezoid");
|
||||
console.log(arrOfShapes);
|
||||
|
||||
let arr5 = [1, 2, 3];
|
||||
let arr6 = [4, 5, 6];
|
||||
let arr7 = arr5.concat(arr6);
|
||||
console.log(arr7);
|
||||
|
||||
let arr8 = arr7.concat(7, 8, 9);
|
||||
console.log(arr8);
|
||||
|
||||
arr8.pop();
|
||||
console.log(arr8);
|
||||
|
||||
arr8.shift();
|
||||
console.log(arr8);
|
||||
|
||||
arr8.splice(1, 3);
|
||||
console.log(arr8);
|
||||
|
||||
delete arr8[0];
|
||||
console.log(arr8);
|
||||
|
||||
let findValue = arr8.find(() => e === 6);
|
||||
let findValue2 = arr8.find(() => e === 8);
|
||||
console.log(findValue, findValue2);
|
||||
|
||||
let findIndex = arr8.indexOf(6);
|
||||
let findIndex2 = arr8.indexOf(10);
|
||||
let findIndex3 = arr8.indexOf(6, 2);
|
||||
console.log(findIndex, findIndex2, findIndex3);
|
||||
|
||||
let animals = ["dog", "horse", "cat", "platypus", "dog"]
|
||||
let lastDog = animals.lastIndexOf("dog");
|
||||
console.log(lastDog);
|
||||
|
||||
|
||||
let names = ["James", "Alicia", "Fatiha", "Maria", "Bert"];
|
||||
names.sort();
|
||||
|
||||
let ages = [18, 72, 33, 56, 40];
|
||||
ages.sort();
|
||||
|
||||
console.log(names);
|
||||
console.log(ages);
|
||||
|
||||
names.reverse();
|
||||
console.log(names);
|
||||
|
||||
console.log(typeof arr1);
|
||||
|
||||
let dog = { dogName: "JavaScript",
|
||||
weight: 2.4,
|
||||
color: "brown",
|
||||
Executable
+49
@@ -0,0 +1,49 @@
|
||||
// let rain = true;
|
||||
|
||||
// if(rain){
|
||||
// console.log("** Taking my umbrella when I need to go outside **");
|
||||
// } else {
|
||||
// console.log("** I can leave my umbrella at home **");
|
||||
// }
|
||||
|
||||
// if(expression) {
|
||||
// // code associated with the if block
|
||||
// // will only be executed if the expression is true
|
||||
// } else {
|
||||
// // code associated with the else block
|
||||
// // we don't need an else block, it is optional
|
||||
// // this code will only be executed if the expression is false
|
||||
// }
|
||||
|
||||
let age = 16;
|
||||
|
||||
if(age < 18) {
|
||||
console.log("We're very sorry, but you can't get in under 18");
|
||||
} else {
|
||||
console.log("Welcome!");
|
||||
}
|
||||
|
||||
if(age < 3){
|
||||
console.log("Access is free under three.");
|
||||
} else if(age >=3 && age < 12) {
|
||||
console.log("With the child discount, the access fee is 5 dollar");
|
||||
} else if(age >=12 && age < 65) {
|
||||
console.log("A regular ticket costs 10 dollar.");
|
||||
} else if(age >= 65) {
|
||||
console.log("A ticket is 7 dollars.");
|
||||
}
|
||||
|
||||
if(age < 3){
|
||||
console.log("Access is free under three.");
|
||||
} else if(age < 12) {
|
||||
console.log("With the child discount, the access fee is 5 dollar");
|
||||
} else if(age < 65) {
|
||||
console.log("A regular ticket costs 10 dollar.");
|
||||
} else if(age >= 65) {
|
||||
console.log("A ticket is 7 dollars.");
|
||||
}
|
||||
|
||||
let access = age < 18 ? "denied" : "allowed";
|
||||
console.log(access);
|
||||
|
||||
age < 18 ? console.log("denied") : console.log("allowed");
|
||||
@@ -1,53 +1,3 @@
|
||||
// let rain = true;
|
||||
|
||||
// if(rain){
|
||||
// console.log("** Taking my umbrella when I need to go outside **");
|
||||
// } else {
|
||||
// console.log("** I can leave my umbrella at home **");
|
||||
// }
|
||||
|
||||
// if(expression) {
|
||||
// // code associated with the if block
|
||||
// // will only be executed if the expression is true
|
||||
// } else {
|
||||
// // code associated with the else block
|
||||
// // we don't need an else block, it is optional
|
||||
// // this code will only be executed if the expression is false
|
||||
// }
|
||||
|
||||
let age = 16;
|
||||
|
||||
if(age < 18) {
|
||||
console.log("We're very sorry, but you can't get in under 18");
|
||||
} else {
|
||||
console.log("Welcome!");
|
||||
}
|
||||
|
||||
if(age < 3){
|
||||
console.log("Access is free under three.");
|
||||
} else if(age >=3 && age < 12) {
|
||||
console.log("With the child discount, the access fee is 5 dollar");
|
||||
} else if(age >=12 && age < 65) {
|
||||
console.log("A regular ticket costs 10 dollar.");
|
||||
} else if(age >= 65) {
|
||||
console.log("A ticket is 7 dollars.");
|
||||
}
|
||||
|
||||
if(age < 3){
|
||||
console.log("Access is free under three.");
|
||||
} else if(age < 12) {
|
||||
console.log("With the child discount, the access fee is 5 dollar");
|
||||
} else if(age < 65) {
|
||||
console.log("A regular ticket costs 10 dollar.");
|
||||
} else if(age >= 65) {
|
||||
console.log("A ticket is 7 dollars.");
|
||||
}
|
||||
|
||||
let access = age < 18 ? "denied" : "allowed";
|
||||
console.log(access);
|
||||
|
||||
age < 18 ? console.log("denied") : console.log("allowed");
|
||||
|
||||
let activity = "Lunch";
|
||||
|
||||
if(activity === "Get up") {
|
||||
-124
@@ -1,127 +1,3 @@
|
||||
let i = 0;
|
||||
while (i < 10) {
|
||||
console.log(i);
|
||||
i++;
|
||||
}
|
||||
|
||||
let someArray = ["Mike", "Antal", "Marc", "Emir", "Louiza", "Jacky"];
|
||||
let notFound = true;
|
||||
|
||||
while (notFound && someArray.length > 0) {
|
||||
if (someArray[0] === "Louiza") {
|
||||
console.log("Found her!");
|
||||
notFound = false;
|
||||
} else {
|
||||
someArray.shift();
|
||||
}
|
||||
}
|
||||
|
||||
console.log(someArray);
|
||||
|
||||
let nr1 = 0;
|
||||
let nr2 = 1;
|
||||
let temp;
|
||||
fibonacciArray = [];
|
||||
|
||||
while (fibonacciArray.length < 25) {
|
||||
fibonacciArray.push(nr1);
|
||||
temp = nr1 + nr2;
|
||||
nr1 = nr2;
|
||||
nr2 = temp;
|
||||
}
|
||||
|
||||
console.log(fibonacciArray);
|
||||
|
||||
do {
|
||||
// code to be executed if the condition is true
|
||||
} while (true);
|
||||
|
||||
let number;
|
||||
do {
|
||||
number = prompt("Please enter a number between 0 and 100: ");
|
||||
} while (!(number >= 0 && number < 100));
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
console.log(i);
|
||||
}
|
||||
|
||||
let arr = [];
|
||||
for (let i = 0; i < 100; i++) {
|
||||
arr.push(i);
|
||||
}
|
||||
|
||||
let arr = [];
|
||||
for (let i = 0; i < 100; i = i + 2) {
|
||||
arr.push(i);
|
||||
}
|
||||
|
||||
let arrOfArrays = [];
|
||||
for (let i = 0; i < 3; i++) {
|
||||
arrOfArrays.push([]);
|
||||
for (let j = 0; j < 7; j++) {
|
||||
arrOfArrays[i].push(j);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(arrOfArrays);
|
||||
|
||||
let names = ["chantal", "john", "maxime", "bobbi", "jair"];
|
||||
for (let i = 0; i < names.length; i++) {
|
||||
console.log(names[i]);
|
||||
}
|
||||
|
||||
//let names = ["chantal", "john", "maxime", "bobbi", "jair"];
|
||||
for (let i = 0; i < names.length; i++) {
|
||||
names[i] = "hello " + names[i];
|
||||
}
|
||||
console.log(names);
|
||||
|
||||
for (let name of names) {
|
||||
console.log(name);
|
||||
}
|
||||
|
||||
let car = {
|
||||
model: "Golf",
|
||||
make: "Volkswagen",
|
||||
year: 1999,
|
||||
color: "black",
|
||||
};
|
||||
|
||||
for (let prop in car) {
|
||||
console.log(car[prop]);
|
||||
}
|
||||
|
||||
for (let prop in car) {
|
||||
console.log(prop);
|
||||
}
|
||||
|
||||
let cars = [
|
||||
{
|
||||
model: "Golf",
|
||||
make: "Volkswagen",
|
||||
year: 1999,
|
||||
color: "black",
|
||||
},
|
||||
{
|
||||
model: "Picanto",
|
||||
make: "Kia",
|
||||
year: 2020,
|
||||
color: "red",
|
||||
},
|
||||
{
|
||||
model: "Peugeot",
|
||||
make: "208",
|
||||
year: 2021,
|
||||
color: "black",
|
||||
},
|
||||
{
|
||||
model: "Fiat",
|
||||
make: "Punto",
|
||||
year: 2020,
|
||||
color: "black",
|
||||
},
|
||||
];
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
console.log(i);
|
||||
if (i === 4) {
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
do {
|
||||
// code to be executed if the condition is true
|
||||
} while (true);
|
||||
|
||||
let number;
|
||||
do {
|
||||
number = prompt("Please enter a number between 0 and 100: ");
|
||||
} while (!(number >= 0 && number < 100));
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
for (let i = 0; i < 10; i++) {
|
||||
console.log(i);
|
||||
}
|
||||
|
||||
let arr = [];
|
||||
for (let i = 0; i < 100; i++) {
|
||||
arr.push(i);
|
||||
}
|
||||
|
||||
let arr = [];
|
||||
for (let i = 0; i < 100; i = i + 2) {
|
||||
arr.push(i);
|
||||
}
|
||||
|
||||
let arrOfArrays = [];
|
||||
for (let i = 0; i < 3; i++) {
|
||||
arrOfArrays.push([]);
|
||||
for (let j = 0; j < 7; j++) {
|
||||
arrOfArrays[i].push(j);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(arrOfArrays);
|
||||
|
||||
let names = ["chantal", "john", "maxime", "bobbi", "jair"];
|
||||
for (let i = 0; i < names.length; i++) {
|
||||
console.log(names[i]);
|
||||
}
|
||||
|
||||
//let names = ["chantal", "john", "maxime", "bobbi", "jair"];
|
||||
for (let i = 0; i < names.length; i++) {
|
||||
names[i] = "hello " + names[i];
|
||||
}
|
||||
console.log(names);
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
for (let name of names) {
|
||||
console.log(name);
|
||||
}
|
||||
|
||||
let car = {
|
||||
model: "Golf",
|
||||
make: "Volkswagen",
|
||||
year: 1999,
|
||||
color: "black",
|
||||
};
|
||||
|
||||
for (let prop in car) {
|
||||
console.log(car[prop]);
|
||||
}
|
||||
|
||||
for (let prop in car) {
|
||||
console.log(prop);
|
||||
}
|
||||
|
||||
let cars = [
|
||||
{
|
||||
model: "Golf",
|
||||
make: "Volkswagen",
|
||||
year: 1999,
|
||||
color: "black",
|
||||
},
|
||||
{
|
||||
model: "Picanto",
|
||||
make: "Kia",
|
||||
year: 2020,
|
||||
color: "red",
|
||||
},
|
||||
{
|
||||
model: "Peugeot",
|
||||
make: "208",
|
||||
year: 2021,
|
||||
color: "black",
|
||||
},
|
||||
{
|
||||
model: "Fiat",
|
||||
make: "Punto",
|
||||
year: 2020,
|
||||
color: "black",
|
||||
},
|
||||
];
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
let i = 0;
|
||||
while (i < 10) {
|
||||
console.log(i);
|
||||
i++;
|
||||
}
|
||||
|
||||
let someArray = ["Mike", "Antal", "Marc", "Emir", "Louiza", "Jacky"];
|
||||
let notFound = true;
|
||||
|
||||
while (notFound && someArray.length > 0) {
|
||||
if (someArray[0] === "Louiza") {
|
||||
console.log("Found her!");
|
||||
notFound = false;
|
||||
} else {
|
||||
someArray.shift();
|
||||
}
|
||||
}
|
||||
|
||||
console.log(someArray);
|
||||
|
||||
let nr1 = 0;
|
||||
let nr2 = 1;
|
||||
let temp;
|
||||
fibonacciArray = [];
|
||||
|
||||
while (fibonacciArray.length < 25) {
|
||||
fibonacciArray.push(nr1);
|
||||
temp = nr1 + nr2;
|
||||
nr1 = nr2;
|
||||
nr2 = temp;
|
||||
}
|
||||
|
||||
console.log(fibonacciArray);
|
||||
@@ -0,0 +1,59 @@
|
||||
function doingStuffAnonymously() {
|
||||
console.log("Not so secret though.");
|
||||
}
|
||||
|
||||
let functionVariable = function () {
|
||||
console.log("Not so secret though.");
|
||||
};
|
||||
|
||||
functionVariable();
|
||||
|
||||
function doFlexibleStuff(executeStuff) {
|
||||
executeStuff();
|
||||
console.log("Inside doFlexibleStuffFunction.");
|
||||
}
|
||||
|
||||
doFlexibleStuff(functionVariable);
|
||||
|
||||
let anotherFunctionVariable = function () {
|
||||
console.log("Another anonymous function implementation.");
|
||||
};
|
||||
|
||||
doFlexibleStuff(anotherFunctionVariable);
|
||||
|
||||
function doOuterFunctionStuff(nr) {
|
||||
console.log("Outer function");
|
||||
doInnerFunctionStuff(nr);
|
||||
function doInnerFunctionStuff(x) {
|
||||
console.log(x + 7);
|
||||
console.log("I can access outer variables:", nr);
|
||||
}
|
||||
}
|
||||
|
||||
doOuterFunctionStuff(2);
|
||||
|
||||
function doOuterFunctionStuff(nr) {
|
||||
doInnerFunctionStuff(nr);
|
||||
function doInnerFunctionStuff(x) {
|
||||
let z = 10;
|
||||
}
|
||||
console.log("Not accessible:", z);
|
||||
}
|
||||
|
||||
doOuterFunctionStuff(2);
|
||||
|
||||
function doOuterFunctionStuff(nr) {
|
||||
doInnerFunctionStuff(nr);
|
||||
function doInnerFunctionStuff(x) {
|
||||
let z = 10;
|
||||
}
|
||||
}
|
||||
|
||||
doInnerFunctionStuff(3);
|
||||
|
||||
let youGotThis = function () {
|
||||
console.log("You're doing really well, keep coding!");
|
||||
};
|
||||
|
||||
setTimeout(youGotThis, 1000);
|
||||
setInterval(youGotThis, 1000);
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
function hiThere() {
|
||||
let you = prompt("What's your name? ");
|
||||
console.log("Hello", you, "!");
|
||||
}
|
||||
|
||||
hiThere();
|
||||
|
||||
console.log("this is an argument");
|
||||
prompt("argument here too");
|
||||
|
||||
let arr = [];
|
||||
arr.push("argument");
|
||||
|
||||
function addTwoNumbers(x, y) {
|
||||
console.log(x + y);
|
||||
}
|
||||
|
||||
addTwoNumbers(3, 4);
|
||||
addTwoNumbers(12, -90);
|
||||
|
||||
function myFunc(param1, param2) {
|
||||
// code of the function;
|
||||
}
|
||||
|
||||
myFunc("arg1", "arg2");
|
||||
|
||||
function addTwoNumbers(x = 2, y = 3) {
|
||||
console.log(x + y);
|
||||
}
|
||||
|
||||
addTwoNumbers();
|
||||
addTwoNumbers(6, 6);
|
||||
addTwoNumbers(10);
|
||||
|
||||
let favoriteSubject = prompt("What is your favorite subject?");
|
||||
|
||||
let result = addTwoNumbers(4, 5);
|
||||
console.log(result);
|
||||
|
||||
function addTwoNumbers(x, y) {
|
||||
return x + y;
|
||||
}
|
||||
|
||||
let results = [];
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
let result = addTwoNumbers(i, 2 * i);
|
||||
results.push(result);
|
||||
}
|
||||
|
||||
console.log(results);
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
function getRecursive(nr) {
|
||||
console.log(nr);
|
||||
getRecursive(--nr);
|
||||
}
|
||||
|
||||
getRecursive(3);
|
||||
|
||||
function logRecursive(nr) {
|
||||
console.log("Started function:", nr);
|
||||
if (nr > 0) {
|
||||
logRecursive(nr - 1);
|
||||
} else {
|
||||
console.log("done with recursion");
|
||||
}
|
||||
console.log("Ended function:", nr);
|
||||
}
|
||||
|
||||
logRecursive(3);
|
||||
|
||||
function getRecursive(nr) {
|
||||
console.log(nr);
|
||||
if (nr > 0) {
|
||||
getRecursive(--nr);
|
||||
}
|
||||
}
|
||||
|
||||
getRecursive(3);
|
||||
|
||||
function calcFactorial(nr) {
|
||||
if (nr === 0) {
|
||||
return 1;
|
||||
} else {
|
||||
return nr * calcFactorial(--nr);
|
||||
}
|
||||
}
|
||||
Executable
+72
@@ -0,0 +1,72 @@
|
||||
function testAvailability(x) {
|
||||
console.log("Available here:", x);
|
||||
}
|
||||
|
||||
testAvailability("Hi!");
|
||||
console.log("Not available here:", x);
|
||||
|
||||
function testAvailability() {
|
||||
let y = "Local variable!";
|
||||
console.log("Available here:", y);
|
||||
}
|
||||
|
||||
testAvailability();
|
||||
console.log("Not available here:", y);
|
||||
|
||||
function testAvailability() {
|
||||
let y = "I'll return";
|
||||
console.log("Available here:", y);
|
||||
return y;
|
||||
}
|
||||
|
||||
let z = testAvailability();
|
||||
console.log("Outside the function:", z);
|
||||
console.log("Not available here:", y);
|
||||
|
||||
let globalVar = "Accessible everywhere!";
|
||||
console.log("Outside function:", globalVar);
|
||||
|
||||
function creatingNewScope(x) {
|
||||
console.log("Access to global variables from inside functions.", globalVar);
|
||||
}
|
||||
|
||||
creatingNewScope("some parameter");
|
||||
|
||||
console.log("Still available:", globalVar);
|
||||
|
||||
function doingStuff() {
|
||||
if (true) {
|
||||
var x = "local";
|
||||
}
|
||||
console.log(x);
|
||||
}
|
||||
|
||||
doingStuff();
|
||||
|
||||
function doingStuff() {
|
||||
if (true) {
|
||||
let x = "local";
|
||||
}
|
||||
console.log(x);
|
||||
}
|
||||
|
||||
doingStuff();
|
||||
|
||||
let x = "global";
|
||||
|
||||
function doingStuff() {
|
||||
let x = "local";
|
||||
console.log(x);
|
||||
}
|
||||
|
||||
doingStuff();
|
||||
|
||||
var x = "global";
|
||||
|
||||
function confuseReader() {
|
||||
x = "Guess my scope...";
|
||||
console.log("Inside the function:", x);
|
||||
}
|
||||
|
||||
confuseReader();
|
||||
console.log("Outside of function:", x);
|
||||
@@ -1,220 +0,0 @@
|
||||
function hiThere() {
|
||||
let you = prompt("What's your name? ");
|
||||
console.log("Hello", you, "!");
|
||||
}
|
||||
|
||||
hiThere();
|
||||
|
||||
console.log("this is an argument");
|
||||
prompt("argument here too");
|
||||
|
||||
let arr = [];
|
||||
arr.push("argument");
|
||||
|
||||
function addTwoNumbers(x, y) {
|
||||
console.log(x + y);
|
||||
}
|
||||
|
||||
addTwoNumbers(3, 4);
|
||||
addTwoNumbers(12, -90);
|
||||
|
||||
function myFunc(param1, param2) {
|
||||
// code of the function;
|
||||
}
|
||||
|
||||
myFunc("arg1", "arg2");
|
||||
|
||||
function addTwoNumbers(x = 2, y = 3) {
|
||||
console.log(x + y);
|
||||
}
|
||||
|
||||
addTwoNumbers();
|
||||
addTwoNumbers(6, 6);
|
||||
addTwoNumbers(10);
|
||||
|
||||
let favoriteSubject = prompt("What is your favorite subject?");
|
||||
|
||||
let result = addTwoNumbers(4, 5);
|
||||
console.log(result);
|
||||
|
||||
function addTwoNumbers(x, y) {
|
||||
return x + y;
|
||||
}
|
||||
|
||||
let results = [];
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
let result = addTwoNumbers(i, 2 * i);
|
||||
results.push(result);
|
||||
}
|
||||
|
||||
console.log(results);
|
||||
|
||||
function testAvailability(x) {
|
||||
console.log("Available here:", x);
|
||||
}
|
||||
|
||||
testAvailability("Hi!");
|
||||
console.log("Not available here:", x);
|
||||
|
||||
function testAvailability() {
|
||||
let y = "Local variable!";
|
||||
console.log("Available here:", y);
|
||||
}
|
||||
|
||||
testAvailability();
|
||||
console.log("Not available here:", y);
|
||||
|
||||
function testAvailability() {
|
||||
let y = "I'll return";
|
||||
console.log("Available here:", y);
|
||||
return y;
|
||||
}
|
||||
|
||||
let z = testAvailability();
|
||||
console.log("Outside the function:", z);
|
||||
console.log("Not available here:", y);
|
||||
|
||||
let globalVar = "Accessible everywhere!";
|
||||
console.log("Outside function:", globalVar);
|
||||
|
||||
function creatingNewScope(x) {
|
||||
console.log("Access to global variables from inside functions.", globalVar);
|
||||
}
|
||||
|
||||
creatingNewScope("some parameter");
|
||||
|
||||
console.log("Still available:", globalVar);
|
||||
|
||||
function doingStuff() {
|
||||
if (true) {
|
||||
var x = "local";
|
||||
}
|
||||
console.log(x);
|
||||
}
|
||||
|
||||
doingStuff();
|
||||
|
||||
function doingStuff() {
|
||||
if (true) {
|
||||
let x = "local";
|
||||
}
|
||||
console.log(x);
|
||||
}
|
||||
|
||||
doingStuff();
|
||||
|
||||
let x = "global";
|
||||
|
||||
function doingStuff() {
|
||||
let x = "local";
|
||||
console.log(x);
|
||||
}
|
||||
|
||||
doingStuff();
|
||||
|
||||
var x = "global";
|
||||
|
||||
function confuseReader() {
|
||||
x = "Guess my scope...";
|
||||
console.log("Inside the function:", x);
|
||||
}
|
||||
|
||||
confuseReader();
|
||||
console.log("Outside of function:", x);
|
||||
|
||||
function getRecursive(nr) {
|
||||
console.log(nr);
|
||||
getRecursive(--nr);
|
||||
}
|
||||
|
||||
getRecursive(3);
|
||||
|
||||
function logRecursive(nr) {
|
||||
console.log("Started function:", nr);
|
||||
if (nr > 0) {
|
||||
logRecursive(nr - 1);
|
||||
} else {
|
||||
console.log("done with recursion");
|
||||
}
|
||||
console.log("Ended function:", nr);
|
||||
}
|
||||
|
||||
logRecursive(3);
|
||||
|
||||
function getRecursive(nr) {
|
||||
console.log(nr);
|
||||
if (nr > 0) {
|
||||
getRecursive(--nr);
|
||||
}
|
||||
}
|
||||
|
||||
getRecursive(3);
|
||||
|
||||
function calcFactorial(nr) {
|
||||
if (nr === 0) {
|
||||
return 1;
|
||||
} else {
|
||||
return nr * calcFactorial(--nr);
|
||||
}
|
||||
}
|
||||
|
||||
function doingStuffAnonymously() {
|
||||
console.log("Not so secret though.");
|
||||
}
|
||||
|
||||
let functionVariable = function () {
|
||||
console.log("Not so secret though.");
|
||||
};
|
||||
|
||||
functionVariable();
|
||||
|
||||
function doFlexibleStuff(executeStuff) {
|
||||
executeStuff();
|
||||
console.log("Inside doFlexibleStuffFunction.");
|
||||
}
|
||||
|
||||
doFlexibleStuff(functionVariable);
|
||||
|
||||
let anotherFunctionVariable = function () {
|
||||
console.log("Another anonymous function implementation.");
|
||||
};
|
||||
|
||||
doFlexibleStuff(anotherFunctionVariable);
|
||||
|
||||
function doOuterFunctionStuff(nr) {
|
||||
console.log("Outer function");
|
||||
doInnerFunctionStuff(nr);
|
||||
function doInnerFunctionStuff(x) {
|
||||
console.log(x + 7);
|
||||
console.log("I can access outer variables:", nr);
|
||||
}
|
||||
}
|
||||
|
||||
doOuterFunctionStuff(2);
|
||||
|
||||
function doOuterFunctionStuff(nr) {
|
||||
doInnerFunctionStuff(nr);
|
||||
function doInnerFunctionStuff(x) {
|
||||
let z = 10;
|
||||
}
|
||||
console.log("Not accessible:", z);
|
||||
}
|
||||
|
||||
doOuterFunctionStuff(2);
|
||||
|
||||
function doOuterFunctionStuff(nr) {
|
||||
doInnerFunctionStuff(nr);
|
||||
function doInnerFunctionStuff(x) {
|
||||
let z = 10;
|
||||
}
|
||||
}
|
||||
|
||||
doInnerFunctionStuff(3);
|
||||
|
||||
let youGotThis = function () {
|
||||
console.log("You're doing really well, keep coding!");
|
||||
};
|
||||
|
||||
setTimeout(youGotThis, 1000);
|
||||
setInterval(youGotThis, 1000);
|
||||
@@ -0,0 +1,41 @@
|
||||
let arr = ["grapefruit", 4, "hello", 5.6, true];
|
||||
function printStuff(element, index) {
|
||||
console.log("Printing stuff:", element, "on array position:", index);
|
||||
}
|
||||
|
||||
let arr = ["squirrel", 5, "Tjed", new Date(), true];
|
||||
function checkString(element, index) {
|
||||
return typeof element === "string";
|
||||
}
|
||||
let filterArr = arr.filter(checkString);
|
||||
console.log(filterArr);
|
||||
|
||||
console.log(arr.every(checkString));
|
||||
|
||||
arr = ["grapefruit", 4, "hello", 5.6, true];
|
||||
arr.copyWithin(0, 3, 4);
|
||||
|
||||
arr = ["grapefruit", 4, "hello", 5.6, true];
|
||||
arr.copyWithin(0, 3, 5);
|
||||
|
||||
let arr = ["grapefruit", 4, "hello", 5.6, true, false];
|
||||
arr.copyWithin(0, 3);
|
||||
console.log(arr);
|
||||
|
||||
let arr = [1, 2, 3, 4];
|
||||
let mapped_arr = arr.map(x => x + 1);
|
||||
console.log(mapped_arr);
|
||||
|
||||
let bb = ["so", "bye", "bye", "love"];
|
||||
console.log(bb.lastIndexOf("bye"));
|
||||
|
||||
let bb = ["so", "bye", "bye", "love"];
|
||||
console.log(bb.lastIndexOf("hi"));
|
||||
|
||||
let letters = ["a", "b", "c"];
|
||||
let x = letters.join();
|
||||
console.log(x);
|
||||
|
||||
let letters = ["a", "b", "c"];
|
||||
let x = letters.join('-');
|
||||
console.log(x);
|
||||
@@ -0,0 +1,50 @@
|
||||
let currentDateTime = new Date();
|
||||
console.log(currentDateTime);
|
||||
|
||||
let now2 = Date.now();
|
||||
console.log(now2);
|
||||
|
||||
let milliDate = new Date(1000);
|
||||
console.log(milliDate);
|
||||
|
||||
let stringDate = new Date("Sat Jun 05 2021 12:40:12 GMT+0200");
|
||||
console.log(stringDate);
|
||||
|
||||
let specificDate = new Date(2022, 1, 10, 12, 10, 15, 100);
|
||||
console.log(specificDate);
|
||||
|
||||
let d = new Date();
|
||||
console.log("Day of week:", d.getDay());
|
||||
console.log("Day of month:", d.getDate());
|
||||
console.log("Month:", d.getMonth());
|
||||
console.log("Year:", d.getFullYear());
|
||||
console.log("Seconds:", d.getSeconds());
|
||||
console.log("Milliseconds:", d.getMilliseconds());
|
||||
console.log("Time:", d.getTime());
|
||||
|
||||
d.setFullYear(2010);
|
||||
console.log(d);
|
||||
|
||||
d.setMonth(9);
|
||||
console.log(d);
|
||||
|
||||
d.setDate(10);
|
||||
console.log(d);
|
||||
|
||||
d.setHours(10);
|
||||
console.log(d);
|
||||
|
||||
d.setTime(1622889770682);
|
||||
console.log(d);
|
||||
|
||||
let d1 = Date.parse("June 5, 2021");
|
||||
console.log(d1);
|
||||
|
||||
let d2 = Date.parse("6/5/2021");
|
||||
console.log(d2);
|
||||
|
||||
console.log(d.toDateString());
|
||||
|
||||
console.log(d.toLocaleDateString());
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
let uri = "https://www.example.com/submit?name=maaike van putten";
|
||||
let encoded_uri = encodeURI(uri);
|
||||
console.log("Encoded:", encoded_uri);
|
||||
let decoded_uri = decodeURI(encoded_uri);
|
||||
console.log("Decoded:", decoded_uri);
|
||||
|
||||
let uri = "https://www.example.com/submit?name=maaike van putten";
|
||||
let encoded_uri = encodeURIComponent(uri);
|
||||
console.log("Encoded:", encoded_uri);
|
||||
let decoded_uri = decodeURIComponent(encoded_uri);
|
||||
console.log("Decoded:", decoded_uri);
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<html>
|
||||
|
||||
<body>
|
||||
<input onchange="go(this)"></input>
|
||||
<script>
|
||||
function go(e) {
|
||||
eval(e.value);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,7 @@
|
||||
let s = "Hello";
|
||||
console.log(
|
||||
s.concat(" there!")
|
||||
.toUpperCase()
|
||||
.replace("THERE", "you")
|
||||
.concat(" You're amazing!")
|
||||
);
|
||||
@@ -0,0 +1,3 @@
|
||||
let x = 7;
|
||||
console.log(Number.isNaN(x));
|
||||
console.log(isNaN(x));
|
||||
@@ -0,0 +1,43 @@
|
||||
let highest = Math.max(2, 56, 12, 1, 233, 4);
|
||||
console.log(highest);
|
||||
|
||||
let lowest = Math.min(2, 56, 12, 1, 233, 4);
|
||||
console.log(lowest);
|
||||
|
||||
let highestOfWords = Math.max("hi", 3, "bye");
|
||||
console.log(highestOfWords);
|
||||
|
||||
let result = Math.sqrt(64);
|
||||
console.log(result);
|
||||
|
||||
let result2 = Math.pow(5, 3);
|
||||
console.log(result2);
|
||||
|
||||
let x = 6.78;
|
||||
let y = 5.34;
|
||||
console.log("X:", x, "becomes", Math.round(x));
|
||||
console.log("Y:", y, "becomes", Math.round(y));
|
||||
|
||||
console.log("X:", x, "becomes", Math.ceil(x));
|
||||
console.log("Y:", y, "becomes", Math.ceil(y));
|
||||
|
||||
let negativeX = -x;
|
||||
let negativeY = -y;
|
||||
console.log("negativeX:", negativeX, "becomes", Math.ceil(negativeX));
|
||||
console.log("negativeY:", negativeY, "becomes", Math.ceil(negativeY));
|
||||
|
||||
console.log("X:", x, "becomes", Math.floor(x));
|
||||
console.log("Y:", y, "becomes", Math.floor(y));
|
||||
|
||||
console.log("negativeX:", negativeX, "becomes", Math.floor(negativeX));
|
||||
console.log("negativeY:", negativeY, "becomes", Math.floor(negativeY));
|
||||
|
||||
console.log("X:", x, "becomes", Math.trunc(x));
|
||||
console.log("Y:", y, "becomes", Math.trunc(y));
|
||||
|
||||
let x = 2;
|
||||
let exp = Math.exp(x);
|
||||
console.log("Exp:", exp);
|
||||
let log = Math.log(exp);
|
||||
console.log("Log:", log);
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
let x = 34;
|
||||
console.log(isNaN(x));
|
||||
console.log(!isNaN(x));
|
||||
let str = "hi";
|
||||
console.log(isNaN(str));
|
||||
|
||||
let str1 = "5";
|
||||
console.log(isNaN(str1));
|
||||
|
||||
let x = 3;
|
||||
let str = "finite";
|
||||
console.log(isFinite(x));
|
||||
console.log(isFinite(str));
|
||||
console.log(isFinite(Infinity));
|
||||
console.log(isFinite(10 / 0));
|
||||
|
||||
let x = 3;
|
||||
let str = "integer";
|
||||
console.log(Number.isInteger(x));
|
||||
console.log(Number.isInteger(str));
|
||||
console.log(Number.isInteger(Infinity));
|
||||
console.log(Number.isInteger(2.4));
|
||||
|
||||
let x = 1.23456;
|
||||
let newX = x.toFixed(2);
|
||||
|
||||
let x = 1.23456;
|
||||
let newX = x.toFixed(3);
|
||||
console.log(x, newX);
|
||||
|
||||
let x = 1.23456;
|
||||
let newX = x.toPrecision(2);
|
||||
|
||||
let x = 1.23456;
|
||||
let newX = x.toPrecision(4);
|
||||
console.log(newX)
|
||||
@@ -0,0 +1,36 @@
|
||||
let str_int = "6";
|
||||
let int_int = parseInt(str_int);
|
||||
console.log("Type of ", int_int, "is", typeof int_int);
|
||||
|
||||
|
||||
let str_float = "7.6";
|
||||
let int_float = parseInt(str_float);
|
||||
console.log("Type of", int_float, "is", typeof int_float);
|
||||
|
||||
let str_binary = "0b101";
|
||||
let int_binary = parseInt(str_binary);
|
||||
console.log("Type of", int_binary, "is", typeof int_binary);
|
||||
|
||||
let str_nan = "hello!";
|
||||
let int_nan = parseInt(str_nan);
|
||||
console.log("Type of", int_nan, "is", typeof int_nan);
|
||||
|
||||
let str_float = "7.6";
|
||||
let float_float = parseFloat(str_float);
|
||||
console.log("Type of", float_float, "is", typeof float_float);
|
||||
|
||||
let str_version_nr = "2.3.4";
|
||||
let float_version_nr = parseFloat(str_version_nr);
|
||||
console.log("Type of", float_version_nr, "is", typeof float_version_nr);
|
||||
|
||||
let str_int = "6";
|
||||
let float_int = parseFloat(str_int);
|
||||
console.log("Type of", float_int, "is", typeof float_int);
|
||||
|
||||
let str_binary = "0b101";
|
||||
let float_binary = parseFloat(str_binary);
|
||||
console.log("Type of", float_binary, "is", typeof float_binary);
|
||||
|
||||
let str_nan = "hello!";
|
||||
let float_nan = parseFloat(str_nan);
|
||||
console.log("Type of", float_nan, "is", typeof float_nan);
|
||||
@@ -0,0 +1,95 @@
|
||||
let s1 = "Hello ";
|
||||
let s2 = "JavaScript";
|
||||
let result = s1.concat(s2);
|
||||
console.log(result);
|
||||
|
||||
let result = "Hello JavaScript";
|
||||
let arr_result = result.split(" ");
|
||||
console.log(arr_result);
|
||||
|
||||
let favoriteFruits = "strawberry,watermelon,grapefruit";
|
||||
let arr_fruits = favoriteFruits.split(",");
|
||||
console.log(arr_fruits);
|
||||
|
||||
let letters = ["a", "b", "c"];
|
||||
let x = letters.join();
|
||||
console.log(x);
|
||||
|
||||
let letters = ["a", "b", "c"];
|
||||
let x = letters.join('-');
|
||||
console.log(x);
|
||||
|
||||
let poem = "Roses are red, violets are blue, if I can do JS, then you can too!";
|
||||
let index_re = poem.indexOf("re");
|
||||
console.log(index_re);
|
||||
|
||||
let indexNotFound = poem.indexOf("python");
|
||||
console.log(indexNotFound);
|
||||
|
||||
if (poem.indexOf("python") != -1) {
|
||||
// do stuff
|
||||
}
|
||||
|
||||
let searchStr = "When I see my fellow, I say hello";
|
||||
let pos = searchStr.search("lo");
|
||||
console.log(pos);
|
||||
|
||||
let notFound = searchStr.search("JavaScript");
|
||||
console.log(notFound);
|
||||
|
||||
let lastIndex_re = poem.lastIndexOf("re");
|
||||
console.log(lastIndex_re);
|
||||
|
||||
let pos1 = poem.charAt(10);
|
||||
console.log(pos1);
|
||||
|
||||
let pos2 = poem.charAt(1000);
|
||||
console.log(pos2);
|
||||
|
||||
let str = "Create a substring";
|
||||
let substr1 = str.slice(5);
|
||||
let substr2 = str.slice(0,3);
|
||||
console.log("1:", substr1);
|
||||
console.log("2:", substr2);
|
||||
|
||||
let hi = "Hi buddy";
|
||||
let new_hi = hi.replace("buddy", "Pascal");
|
||||
console.log(new_hi);
|
||||
|
||||
let new_hi2 = hi.replace("not there", "never there");
|
||||
console.log(new_hi2);
|
||||
|
||||
let s3 = "hello hello";
|
||||
let new_s3 = s3.replace("hello", "oh");
|
||||
console.log(new_s3);
|
||||
|
||||
let s3 = "hello hello";
|
||||
let new_s3 = s3.replaceAll("hello", "oh");
|
||||
console.log(new_s3);
|
||||
|
||||
let low_bye = "bye!";
|
||||
let up_bye = low_bye.toUpperCase();
|
||||
console.log(up_bye);
|
||||
|
||||
let caps = "HI HOW ARE YOU?";
|
||||
let fixed_caps = caps.toLowerCase();
|
||||
console.log(fixed_caps);
|
||||
|
||||
let caps = "HI HOW ARE YOU?";
|
||||
let fixed_caps = caps.toLowerCase();
|
||||
let first_capital = fixed_caps.charAt(0).toUpperCase().concat(fixed_caps.slice(1));
|
||||
console.log(first_capital);
|
||||
|
||||
let encouragement = "You are doing great, keep up the good work!";
|
||||
let bool_start = encouragement.startsWith("You");
|
||||
console.log(bool_start);
|
||||
|
||||
let bool_start2 = encouragement.startsWith("you");
|
||||
console.log(bool_start2);
|
||||
|
||||
let bool_start3 = encouragement.toLowerCase().startsWith("you");
|
||||
console.log(bool_start3);
|
||||
|
||||
let bool_end = encouragement.endsWith("Something else");
|
||||
console.log(bool_end);
|
||||
|
||||
Reference in New Issue
Block a user