RearangeClockMiniProjectAndOthers
This commit is contained in:
12
Practice/TimesDatesTimers/index.html
Normal file
12
Practice/TimesDatesTimers/index.html
Normal file
@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>For every output check out the console!!!</h1>
|
||||
<script src="script.js"></script>
|
||||
</body>
|
||||
</html>
|
45
Practice/TimesDatesTimers/script.js
Normal file
45
Practice/TimesDatesTimers/script.js
Normal file
@ -0,0 +1,45 @@
|
||||
//DATE OBJECTS
|
||||
|
||||
//Date(year, month, day, hours, minutes, seconds, milliseconds)
|
||||
const today = new Date();
|
||||
console.log(today);
|
||||
console.log(today.toLocaleDateString());
|
||||
console.log(today.toLocaleTimeString());
|
||||
console.log(today.toDateString());
|
||||
console.log(today.toTimeString());
|
||||
console.log(today.getTime());
|
||||
|
||||
|
||||
//CLOSURES by using closures we can reuse a function without having to create a new one. And with this we an store variables safely.
|
||||
|
||||
function createCounter(){
|
||||
let count = 0;
|
||||
function increment(){
|
||||
count++;
|
||||
console.log(count);
|
||||
}
|
||||
|
||||
function getCount(){
|
||||
return count;
|
||||
}
|
||||
return {increment};
|
||||
}
|
||||
|
||||
counter = createCounter();
|
||||
counter.increment();
|
||||
counter.increment();
|
||||
counter.increment();
|
||||
|
||||
|
||||
//SETTIMEOUT Note this function is not too precise!
|
||||
|
||||
function hello(){
|
||||
console.log("HOLA");
|
||||
}
|
||||
|
||||
setTimeout(hello, 3000); //It will delay the function by 3 seconds
|
||||
setTimeout( function(){console.log("HOLA")}, 3000);
|
||||
setTimeout(() => window.alert("HOLA"), 3000);
|
||||
|
||||
console.log("HOLA");
|
||||
|
Reference in New Issue
Block a user