updated folder structure

This commit is contained in:
brightboost
2021-11-25 14:40:42 +01:00
parent 3201b7b09c
commit f8bde27fc6
78 changed files with 0 additions and 0 deletions
+129
View File
@@ -0,0 +1,129 @@
let text = "I love JavaScript!";
console.log(text.match(/javascript/));
let text = "I love JavaScript!";
console.log(text.match(/javascript/i));
let text = "I love JavaScript!";
console.log(text.match(/javascript|nodejs|react/i));
let text = "I love React and JavaScript!";
console.log(text.match(/javascript|nodejs|react/i));
let text = "I love React and JavaScript!";
console.log(text.match(/javascript|nodejs|react/gi));
let text = "d";
console.log(text.match(/[abc]/gi));
console.log(text.match(/[a-zA-Z0-9]/));
let text = "Just some text.";
console.log(text.match(/./g));
let text = "Just some text.";
console.log(text.match(/\./g));
let text = "I'm 29 years old.";
console.log(text.match(/\d/g));
let text = "Coding is a lot of fun!";
console.log(text.match(/\s/g));
let text = "In the end or at the beginning?";
console.log(text.match(/\bin/gi));
let text = "I love JavaScript!";
console.log(text.match(/(love|hate)\s(javascript|spiders)/gi));
console.log(text.match(/[a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9]/));
let text = "123123123";
console.log(text.match(/(123)+/g));
let text = "abcabcabcabc";
console.log(text.match(/(abc){1,2}/));
let text = "That's not the case.";
console.log(text.search(/CaSE/i));
let text = "Coding is fun. Coding opens up a lot of opportunities.";
console.log(text.replace("Coding", "Javascript"));
let text = "Coding is fun. Coding opens up a lot of opportunities.";
console.log(text.replace(/Coding/g, "Javascript"));
(function () {
console.log("IIFE!");
})();
function test(a, b, c) {
console.log("first:", a, arguments[0]);
console.log("second:", a, arguments[1]);
console.log("third:", a, arguments[2]);
}
test("fun", "js", "secrets");
function test(a, b, c) {
a = "nice";
arguments[1] = "JavaScript";
console.log("first:", a, arguments[0]);
console.log("second:", a, arguments[1]);
console.log("third:", a, arguments[2]);
}
test("fun", "js", "secrets");
("use strict");
var x;
x = 5;
console.log(x);
x = 5;
console.log(x);
var x;
function sayHi() {
greeting = "Hello!";
console.log(greeting);
}
document.cookie = "name=Maaike;favoriteColor=black";
let cookie = decodeURIComponent(document.cookie);
let cookieList = decodedCookie.split(";");
for (let i = 0; i < cookieList.length; i++) {
let c = cookieList[i];
if (c.charAt(0) == " ") {
c = c.trim();
}
if (c.indexOf("name") == 0) {
return c.substring(4, c.length); //start one later to skip =
}
}
function somethingVeryDangerous() {
throw Error;
}
try {
somethingVeryDangerous();
} catch (e) {
if (e instanceof TypeError) {
// deal with TypeError exceptions
} else if (e instanceof RangeError) {
// deal with RangeError exceptions
} else if (e instanceof EvalError) {
// deal with EvalError exceptions
} else {
//deal with all other exceptions
throw e; //rethrow
}
}
try {
trySomething();
} catch (e) {
console.log("Oh oh");
} finally {
console.log("Error or no error, I will be logged!");
}
@@ -0,0 +1,16 @@
function saySomething(x) {
return new Promise(resolve => {
setTimeout(() => {
resolve('something' + x);
}, 2000);
});
}
async function talk(x) {
const words = await saySomething(x);
console.log(words);
}
talk(2);
talk(4);
talk(8);
+63
View File
@@ -0,0 +1,63 @@
function doSomething(callback) {
callback();
}
function sayHi() {
console.log("Hi!");
}
doSomething(sayHi);
function judge(grade) {
switch (true) {
case grade == "A":
console.log("You got an", grade, ": amazing!");
break;
case grade == "B":
console.log("You got a", grade, ": well done!");
break;
case grade == "C":
console.log("You got a", grade, ": alright.");
break;
case grade == "D":
console.log("You got a", grade, ": hmmm...");
break;
default:
console.log("An", grade, "! What?!");
}
}
function getGrade(score, callback) {
let grade;
switch (true) {
case score >= 90:
grade = "A";
break;
case score >= 80:
console.log(score);
grade = "B";
break;
case score >= 70:
grade = "C";
break;
case score >= 60:
grade = "D";
break;
default:
grade = "F";
}
judge(grade);
}
getGrade(85, judge);
setInterval(500, encourage);
function encourage() {
console.log("You're doing great, keep going!");
}
setInterval(function () {
console.log("You're doing great, keep going!");
}, 500)
@@ -0,0 +1,26 @@
const promise = new Promise((fulfill, reject) => {
fulfill('success!');
//reject('oops...');
})
.then(value => {
console.log(value);
return 'we';
})
.then(value => {
console.log(value);
return 'can';
})
.then(value => {
console.log(value);
return 'chain';
})
.then(value => {
console.log(value);
return 'promises';
})
.then(value => {
console.log(value);
})
.catch(value => {
console.log(value);
})
+34
View File
@@ -0,0 +1,34 @@
{
"companies": [
{
"name": "JavaScript Code Dojo",
"addresses": [
{
"street": "123 Main street",
"zipcode": 12345,
"city" : "Scott"
},
{
"street": "123 Side street",
"zipcode": 35401,
"city" : "Tuscaloosa"
}
]
},
{
"name": "Python Code Dojo",
"addresses": [
{
"street": "123 Party street",
"zipcode": 68863,
"city" : "Nebraska"
},
{
"street": "123 Monty street",
"zipcode": 33306,
"city" : "Florida"
}
]
}
]
}
+33
View File
@@ -0,0 +1,33 @@
<html>
<body>
<input onchange="setCookie(this)" />
<button onclick="sayHi('name')">Let's talk, cookie!</button>
<p id="hi"></p>
<script>
function setCookie(e) {
document.cookie = "name=" + e.value + ";";
}
function sayHi(key) {
let name = getCookie(key);
document.getElementById("hi").innerHTML = "Hi " + name;
}
function getCookie(key) {
let cookie = decodeURIComponent(document.cookie);
let cookieList = cookie.split(";");
for (let i = 0; i < cookieList.length; i++) {
let c = cookieList[i];
if (c.charAt(0) == " ") {
c = c.trim();
}
if (c.startsWith(key)) {
console.log("hi" + c);
return c.substring(key.length + 1, c.length);
}
}
}
</script>
</body>
</html>
+12
View File
@@ -0,0 +1,12 @@
let str = "{\"name\": \"Maaike\", \"age\": 30}";
let obj = JSON.parse(str);
console.log(obj.name, "is", obj.age);
let dog = {
"name": "wiesje",
"breed": "dachshund"
};
let strdog = JSON.stringify(dog);
console.log(typeof strdog);
console.log(strdog);
+19
View File
@@ -0,0 +1,19 @@
let promise = new Promise(function (resolve, reject) {
// do something that might take a while
// let's just set x instead for this example
let x = 20;
if (x > 10) {
resolve(x); // on success
} else {
reject("Too low"); // on error
}
});
promise.then(
function (value) {
console.log("Success:", value)
},
function (error) {
console.log("Error:", error)
}
);
+16
View File
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<body>
<div id="whatname"></div>
<button onclick="whatName()">What name?</button>
<script>
window.localStorage.setItem("name", "That name!");
function whatName() {
window.localStorage.clear();
document.getElementById("whatname").innerText = window.localStorage.getItem("name");
}
</script>
</body>
</html>