MostlyCalculator

This commit is contained in:
2024-10-11 10:55:09 +02:00
parent a94be56583
commit bc4486fe11
5 changed files with 220 additions and 4 deletions

View File

@ -7,6 +7,6 @@
</head>
<body>
<h1>For every output check out the console!!!</h1>
<script src="script.js"></script>
<script type="module" src="script.js" ></script> <!--It is important to use the script as a module!!!-->
</body>
</html>

View File

@ -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
}

View File

@ -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
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!")