Commit 6f12efb0 authored by dbhuller's avatar dbhuller

adding html file and js file contianing concepts covered in training

parents
File added
<!DOCTYPE html>
<html>
<head>
<title>
Basic HTML
</title>
<script type="text/javascript">
function helloWorld() {
document.write('Hello World from Head Tag!');
}
</script>
<script src="./external-js.js"></script>
</head>
<body>
<h1>External/Internal JS</h1>
<script type="text/javascript">
helloWorld();
document.write("<br>");
helloWorldExternal();
</script>
<h1>Using Vars/Funcions</h1>
<script>
varExample();
</script>
<h1>Global/Local Variable Scope</h1>
<script>
document.write("Initial Global var: " + globalVar)
document.write("<br>");
globalTest();
document.write("<br>");
globalTest2();
</script>
<h1>Functions w/ Params</h1>
<script>
funcWithParam("Cat", "Dog");
</script>
<h1>Function w/ Input and Return</h1>
<input id="myInput" type="text">
<button onclick="inputSubmitReturn()" type="submit">Submit</button>
<h1>Anon Function</h1>
<script>
// Function that doesnt have a name
let anonFunc = function (name, session) {
return (`Hello ${name}! Welcome to ${session}.`);
}("Test", 'JavaScript Basics')
document.write(anonFunc);
</script>
<h1>Nested Functions</h1>
<script>
document.write("Passed in 2 and 2, returned squared and added: ");
document.write("<br>");
document.write(add(2, 2));
</script>
<h1>Pre/Post Incrament-Decrament</h1>
<script>
let a = 10;
let preInc = ++a;
let postInc = a++;
document.write(a);
document.write("<br>");
document.write("Pre Incrament: " + preInc);
document.write("<br>");
document.write("Post Incrament: " + postInc);
document.write("<br>");
let b = 10;
let preDec = --b;
let postDec = b--;
document.write(b);
document.write("<br>");
document.write("Pre Decrament: " + preDec);
document.write("<br>");
document.write("Post Decrament: " + postDec);
</script>
<h1>Conditional Statements</h1>
<script>
conditionalDemo("Deep");
document.write("<br>");
conditionalDemo("Test");
</script>
<h1>For-In vs For-Of</h1>
<script>
let myArr = ['a', 'b', 'c', 'd', 'e', 'f'];
arrForIn(myArr);
document.write("<br>")
arrForOf(myArr);
</script>
</body>
</html>
\ No newline at end of file
function helloWorldExternal() {
document.write("Hello world from external js file");
}
let v1 = "dog", v2 = 'cat', v3 = 20;
function varExample() {
document.write("V1: " + v1 + ", " + "V2: " + v2 + ", " + "V3: " + v3);
}
// Global Scope demo
var globalVar = "Im Global"
function globalTest() {
document.write(globalVar);
}
function globalTest2() {
globalVar = "Hello Im Global from globalTest2, my initial value was changed";
document.write(globalVar);
}
function funcWithParam(myParam, myParam2) {
document.write("Function took in args: " + myParam + ", " + myParam2);
}
function inputSubmitReturn(input) {
input = document.getElementById("myInput").value;
return document.write("you entered: " + input);
}
function add(a, b) {
function nestedSquare(x) {
return x * x;
}
return nestedSquare(a) + nestedSquare(b);
}
function conditionalDemo(arg) {
let myArg = "Deep";
if(arg == myArg) {
document.write("You entered the same arg. Entered: " + arg + ", " + " Expected: " + myArg);
} else {
document.write("You didnt enter the same arg. Entered: " + arg + ", " + " Expected: " + myArg);
}
}
function arrForIn(arr) {
document.write("With for-in: ");
for( let val in arr) {
document.write(val);
}
}
function arrForOf(arr) {
document.write("With for-of: ")
for(let val of arr) {
document.write(val);
}
}
\ No newline at end of file
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