-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
63 lines (52 loc) · 1.83 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const x = document.getElementById("demo");
const password = "password";
const btn = document.querySelector("#button");
const blackbtn = document.querySelector("#blackButton");
const textOutput = document.querySelector("#textOutput")
const textInput = document.querySelector("#textInput")
const form = document.querySelector("#textForm");
form.addEventListener("submit", (event) => {
if (textInput === "") {
event.preventDefault();
textOutput.textContent = "You need to enter some valid value.";
}
});
textInput.addEventListener("keydown", displayText);
btn.addEventListener("click", () => {
const rndCol = `rgb(${random(255)}, ${random(255)}, ${random(255)})`;
document.body.style.backgroundColor = rndCol;
});
blackbtn.addEventListener("click", () => {
const black = `rgb(${0}, ${0}, ${0})`;
document.body.style.backgroundColor = black;
});
function displayText(event) {
textOutput.textContent = `You pressed "${event.key}. "`;
}
function random(number) {
return Math.floor(Math.random() * (number + 1));
}
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude;
}
function myFunction() {
document.getElementById('demo').innerHTML = Date()
}
/*
btn.addEventListener("click", () => {
const rndCol = `rgb(${random(255)}, ${random(255)}, ${random(255)})`;
document.body.style.backgroundColor = rndCol;
});
btn.addEventListener("click", changeColor);
function changeColor() {
const rndCol = `rgb(${random(255)}, ${random(255)}, ${random(255)})`;
document.body.style.backgroundColor = rndCol;
}
*/