//both html dom interactions and random JavaScript topics are in this file, document.addEventListener("DOMContentLoaded", ()=> { const body = document.getElementById("bod"); const div = document.createElement("div"); div.innerText = "What time is it?"; body.appendChild(div); let currentTime; const timeDiv = document.createElement("div"); body.appendChild(timeDiv); setInterval(()=>{ currentTime = new Date(); const hours = currentTime.getUTCHours() - 5; const mins = currentTime.getUTCMinutes(); const seconds = currentTime.getUTCSeconds(); timeDiv.innerText = `${ hours > 12 ? hours - 12 : hours}:${mins < 10 ? `0${mins}` : mins}:${seconds < 10 ? `0${seconds}` : seconds} CT`; },1000); //Just JS stuff below function addingRecursion(...args){ if (args.length === 0) return 0; return args[0] + addingRecursion(...args.slice(1)); } console.log(addingRecursion(1,3,4,7,5,3)); function canHardly(num1,num2){ return num1 + (function(){return num2 ** 2;})(); } console.log(canHardly(1,8)); function imGonnaReturnMyself(){ console.log("completing complex algo for self returnation") return imGonnaReturnMyself; } const returned = imGonnaReturnMyself(); const counterFactory = () => { //nifty closure here let count = 0; return ( () => { count++; console.log(count); } ) } const counter1 = counterFactory(); counter1(); counter1(); if (2 == "2"){ let arr = [1785,2 % 5,34, 2 == "2"]; for (let el of arr){ console.log(el); } } const a = 10; switch (a) { case 10: console.log("I'm 10"); break; case 21: console.log("wow"); break; case "10": console.log("string>"); break; } //REVIEW TOPICS FROM PRADEEP // Variables - Scopes const globalScopedVar = "worldwide"; function funcScope(){var funcScopedVar;} if (true){ let blockScopeVar; } // Functions function regFunction (arg){ console.log(arg); } const arrowFunc = () => "look out I'm pointy"; (function(){return "I'm just an IIFE"})(); class ImAClass { static method= () => { console.log("I'm a method of " + this.toString()); } static toString(){ return "ImAClass"; } } const methodFunc = ImAClass.method; methodFunc(); // Operators const add = 2 + 2; const sub = 2 - 10000000; const mult = 4 * 4; const division = 5/5/5; const mod = 10 % 2; const exp = 3**3; // Conditional statements if (true) { const iWill = "do this"; } else if (null === true) { const iWould = "do this instead"; } else { console.log("something bad has happened if you've gotten here"); } //see my switch above // Loops for (let i = 9; i < 100; i += 2){ //something looping about 45 times } let condition = true; while (condition){ let thoughtProcess = "better set this condition to false"; condition = false; } function something(){ console.log("ta da") } do { something(); } while (undefined); //algo: sorted array to balanced binary search tree class Node { constructor(val,left,right){ this.val = val; this.left = left; this.right = right; } } class BinaryTreeMaker { static makeTree(sortedArr){ const midPoint = Math.floor(sortedArr.length / 2); const root = new Node(sortedArr[midPoint], null, null); const leftSide = sortedArr.slice(0, midPoint); const rightSide = sortedArr.slice(midPoint + 1); if (leftSide.length){ root.left = this.makeTree(leftSide); } if (rightSide.length){ root.right = this.makeTree(rightSide); } return root; } } console.log(BinaryTreeMaker.makeTree([3,6,8,9,10,100,433])); console.log("we are at the conclusion, thanks for your time.") })