0007 added[Method chaining, if statements, switch statement, checkboxes, radiobuttons]
This commit is contained in:
53
js/index.js
53
js/index.js
@@ -117,7 +117,7 @@ console.log(students);
|
||||
//console.log(username);
|
||||
//8.2
|
||||
let username;
|
||||
document.getElementById("myButton").onclick = function() {
|
||||
document.getElementById("myButton").onclick = function () {
|
||||
username = document.getElementById("myText").value;
|
||||
console.log(username);
|
||||
document.getElementById("myLabel").innerHTML = username;
|
||||
@@ -172,7 +172,7 @@ console.log(x);
|
||||
x = Math.ceil(7.1); //round number always up
|
||||
console.log(x);
|
||||
|
||||
x = Math.pow(2,8); //pow(base, exponent) gives base to the power of exponent value
|
||||
x = Math.pow(2, 8); //pow(base, exponent) gives base to the power of exponent value
|
||||
console.log(x);
|
||||
|
||||
x = Math.sqrt(9); //get squareroot of number
|
||||
@@ -185,8 +185,8 @@ let c = 5;
|
||||
let d = 9;
|
||||
let max;
|
||||
let min;
|
||||
max = Math.max(c,d); //get maximum out of array with numbers
|
||||
min = Math.min(c,d); //get minimum out of array with numbers
|
||||
max = Math.max(c, d); //get maximum out of array with numbers
|
||||
min = Math.min(c, d); //get minimum out of array with numbers
|
||||
console.log(max);
|
||||
console.log(min);
|
||||
|
||||
@@ -226,4 +226,47 @@ console.log(lastName2);
|
||||
//--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
//14.Method chaining
|
||||
//https://youtu.be/8dWL3wF_OMw?t=3554
|
||||
//Chaining methods...
|
||||
let userName3 = "bro";
|
||||
let letter = userName3.charAt(0).toUpperCase().trim();
|
||||
console.log(letter);
|
||||
//--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
//15.If-statements
|
||||
//Basic form of decission making, if the condition is true, something is done, else it is not done
|
||||
let age4 = 21;
|
||||
if (age4 >= 18) {
|
||||
console.log("You're an adult!");
|
||||
} else if (age < 0) {
|
||||
console.log("You havn't been born yet!");
|
||||
} else if (age >= 65) {
|
||||
console.log("You are a senior citizen!");
|
||||
} else {
|
||||
console.log("You're a child.");
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
//16.Switch-statement
|
||||
//Advanced form of decission-making, if case is true, something is done
|
||||
//examines a value for a match against many case clauses, more efficient, than many else ifs
|
||||
let grade = "A";
|
||||
switch (grade) {
|
||||
case ("A"): {
|
||||
console.log("Very Good Mr!");
|
||||
} break;
|
||||
case ("B"): {
|
||||
console.log("Good Mr!");
|
||||
} break;
|
||||
case ("C"): {
|
||||
console.log("Could be better.");
|
||||
} break;
|
||||
case ("D"): {
|
||||
console.log("Troll!");
|
||||
} break;
|
||||
case ("F"): {
|
||||
console.log("Idiot!");
|
||||
} break;
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
//17.
|
||||
Reference in New Issue
Block a user