From bc4486fe112af640535fa891e3504221ddf7a5b0 Mon Sep 17 00:00:00 2001 From: Kilokem Date: Fri, 11 Oct 2024 10:55:09 +0200 Subject: [PATCH] MostlyCalculator --- MiniProjects/Calculator/calculator.html | 105 ++++++++++++++++++++++++ MiniProjects/Calculator/calculator.js | 51 ++++++++++++ Practice/AdvancedThings/index.html | 2 +- Practice/AdvancedThings/mathUtil.js | 13 +++ Practice/AdvancedThings/script.js | 53 +++++++++++- 5 files changed, 220 insertions(+), 4 deletions(-) create mode 100644 MiniProjects/Calculator/calculator.html create mode 100644 MiniProjects/Calculator/calculator.js create mode 100644 Practice/AdvancedThings/mathUtil.js diff --git a/MiniProjects/Calculator/calculator.html b/MiniProjects/Calculator/calculator.html new file mode 100644 index 0000000..f9423a7 --- /dev/null +++ b/MiniProjects/Calculator/calculator.html @@ -0,0 +1,105 @@ + + + + + + Calculator + + + +
+
+ 0 +
+
+ + + + + + + + + + + + + + + + +
+
+ + + \ No newline at end of file diff --git a/MiniProjects/Calculator/calculator.js b/MiniProjects/Calculator/calculator.js new file mode 100644 index 0000000..97ed356 --- /dev/null +++ b/MiniProjects/Calculator/calculator.js @@ -0,0 +1,51 @@ +var number = 0; +var newNum = true +var operand = null; +function update(num){ + if (newNum){ + document.getElementById("result").innerHTML += num; + }else{ + storenum(num); + } +} + +function clearout(){ + number = 0; + document.getElementById("result").innerHTML = ""; +} + +function storenum(num){ + var currentNumber =Number(document.getElementById("result").innerHTML); + switch (operand){ + case '*': + number = number * currentNumber; + break; + case '/': + number = number / currentNumber; + break; + case '+': + number = number + currentNumber; + break; + case '-': + number = number - currentNumber; + break; + default: + if(number == 0) number = currentNumber; + break; + } + if (num != 0){ + document.getElementById("result").innerHTML = '' + num; + } + console.log(number) + newNum = true; +} + +function operation(simbol){ + operand = simbol; + newNum = false +} + +function showresult(){ + storenum(0); + document.getElementById("result").innerHTML = number; +} \ No newline at end of file diff --git a/Practice/AdvancedThings/index.html b/Practice/AdvancedThings/index.html index cd01ed3..cb398e5 100644 --- a/Practice/AdvancedThings/index.html +++ b/Practice/AdvancedThings/index.html @@ -7,6 +7,6 @@

For every output check out the console!!!

- + \ No newline at end of file diff --git a/Practice/AdvancedThings/mathUtil.js b/Practice/AdvancedThings/mathUtil.js new file mode 100644 index 0000000..aad561a --- /dev/null +++ b/Practice/AdvancedThings/mathUtil.js @@ -0,0 +1,13 @@ + export const PI = 3.14159 + +export function getCircumference(radius){ + return 2 * PI * radius +} + +export function getArea(radius){ + return PI * radius * radius +} + +export function getVolume(radius){ + return (4/3) * PI * radius ** 3 +} \ No newline at end of file diff --git a/Practice/AdvancedThings/script.js b/Practice/AdvancedThings/script.js index 8e193bb..576421d 100644 --- a/Practice/AdvancedThings/script.js +++ b/Practice/AdvancedThings/script.js @@ -1,4 +1,51 @@ -console.log("Hello World"); +//ES6 MODULES -//I shall continue from this poin: -//https://youtu.be/lfmg-EJ8gm4?feature=shared&t=27294 \ No newline at end of file +import {PI, getCircumference, getArea, getVolume} from './mathUtil.js'; //Import functions and variables from another file + +//https://youtu.be/lfmg-EJ8gm4?feature=shared&t=27294 + +console.log(PI) + +console.log("Circumference: " + getCircumference(5)); +console.log("Area: " + getArea(5)); +console.log("Volume: " + getVolume(5)); + + +//ASYNC PROGRAMMING!!! + + +setTimeout(() => console.log("Task1"), 3000) //THIS IS AN ASYNC FUNCTION!!!! And because of that the tasks order will be 2, 3, and 1 + +console.log('Task2') +console.log('Task3') + + //Force async functions to behave like synchronous +function func1(callback){ + setTimeout(() => {console.log("Stask1"); + callback();},3000); +} +function func2(){ + console.log("Stask2"); + console.log("Stask3"); +} +func1(func2); + + +//ERROR OBJECTS + +try{ + console.log("HELLO"); + const feellikeerror = false; + if (feellikeerror){ + throw new Error("I felt like making an error!") + } + +} +catch(error){ + console.error(error) +} +finally{ //OPTIONAL It will always be executed! + console.log("This always executes!") +} + +console.log("END!") \ No newline at end of file