Commit 80200193 authored by Shaphen Pangburn's avatar Shaphen Pangburn

Complete assignment for JavaScript Basics

parents
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Javascript Practice</title>
<script src="js_refresher.js"></script>
<script src="js_practice.js"></script>
<script>
function speak() {
document.write(" /o/");
}
let introduction = name => {
document.write("Hi my name is " + name);
}
</script>
</head>
<body>
<h1>Hello friends</h1>
<script>
document.write("Oh hi there!"); // print statement
speak(); // called function from the header
</script>
<br>
<script>myFunction(); // called from ./javascript_refresher.js</script>
<br>
<script>counter(10); // called from ./javascript_refresher.js</script>
<br>
<script>document.write(thing) // using a global variable</script>
<br>
<script>introduction("Chef") // function created using anonymous function</script>
<br>
<script>
(function(message) {
document.write(`This is a special message: ${message}`);
})("I'm a potato"); // anonymous function that immediately invokes
</script>
<br>
<script>
functionOne();
// functionTwo(); will throw error because not in scope
</script>
</body>
</html>
// nested functions / scope
function functionOne() {
console.log("first function")
function functionTwo() {
console.log("Nested function");
}
}
// incrementation and operators
let a = 10;
console.log(a); // 10
console.log(a++); // 10
console.log(a); // 11
console.log(++a); // 12
console.log("-");
console.log(a += 1); // 13
console.log(a -= 1); // 12
console.log(a *= 2); // 24
console.log(a /= 2); // 12
console.log("-");
// loops and conditionals
let i = true;
while (i == false) {
console.log("I wont show");
}
let j = true;
do {
console.log("I will show");
} while (j == false);
console.log("-");
let arr = ["Pradeep", "Kevin", "Shanelle", "Ben", "Nikitha", "Vishal"]
for (const engineerIdx in arr) {
console.log(engineerIdx);
}
console.log("-");
for (const engineer of arr) {
console.log(engineer);
}
// variable declaration
thing = "ok bye";
console.log(thing);
// function declarations
function myFunction() {
document.write("I'm here too!")
}
function counter(max) {
for (let i = 0; i <= max; i++) {
console.log(i);
document.write(i);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment