Commit ae6a1739 authored by John Lam's avatar John Lam

Initial commit

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>Basic HTML</title>
<script src="first.js"></script>
</head>
<style>
.h2 {
color: blue;
}
.active {
font-size: 100px;
}
</style>
<body>
<div>
<h1>Hello world!</h1>
</div>
<h2 class="h2"></h2>
<script>
var num = 10;
function fn () {
let h2 = document.querySelector(".h2");
h2.classList.toggle('active');
h2.innerHTML = num++;
}
let insideNum = 5;
document.write(insideNum);
document.addEventListener("click", () => {
fn();
})
</script>
<br><br><br>
<script>
function sayHi(personName, session){
return "Hello " + personName + " Welcome to : " + session;
}
let greeting = sayHi("john", "javascript")
document.write(greeting);
</script>
<br> <br>
<script>
function myFunction() {
console.log('inside nested fn');
let str = "closure / nested function"
function nestedFn() {
document.write(str);
}
nestedFn();
}
myFunction();
</script>
<br> <br>
<script>
const anon = function (personName, session) {
return "Hello " + personName + "! Welcome to " + session;
} ("john", 'anonymous functions');
document.write(anon)
</script>
</body>
</html>
\ No newline at end of file
document.write("hi hi hi hi");
console.log("here");
let n = 9;
document.write(n);
<!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">
<script language="javascript" type="text/javascript">
function myFunction() {
document.write("hi thurrrr")
}
</script>
<script src="./js_assignment.js" ></script>
<title>js_assignment</title>
</head>
<body >
</body>
</html>
\ No newline at end of file
function myFunction() {
let str = "closure function"
function nestedFn() {
document.write(str);
}
nestedFn();
}
\ No newline at end of file
// Variables - Scopes
// Functions
// Operators
// Conditional statements
// Loops
let alpha = ["A", "b", "C", "d"]
const count = (arr) => {
let count = 0;
for (ele of alpha) {
if (ele == "b" || ele == "d") {
count +=1;
}
}
return count;
}
console.log("count: " + count(alpha));
const scoping = () => {
let arr = ["hi", "there", "hello"];
console.log(num) // will be undefined
console.log("inside scope")
return () => {
console.log("inside anonymous function within scope")
console.log(arr[2]);
}
var num = 10;
}
scoping()();
let globalArray = ["one", "two", "3"];
function forLoops(array) {
for (let i = 0; i < array.length ; i++) {
console.log(i);
}
}
function forInLoop(array) {
for(let i in array) {
console.log(i);
}
}
function ForOfLoop() {
for (let i of globalArray) {
console.log(i);
}
}
function doWhileLoop() {
let i = 5;
do {
console.log("this will run at least once even though the condition is false");
} while (i < 3);
}
function switchStatement() {
var number = 2;
let msg = "";
switch (number) {
case 1:
tmp = "one";
break;
case 2:
tmp = "two";
break;
case 3:
tmp = "three";
break;
default:
}
console.log(msg);
}
let letter = "A"
function conditionals() {
if (letter == "a") {
console.log("it's a");
} else if (letter == "b") {
console.log("it's b")
} else {
console.log("it's A")
}
}
conditionals();
forLoops(globalArray);
forInLoop(globalArray);
ForOfLoop(globalArray);
doWhileLoop(globalArray);
switchStatement();
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