-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweekNine.js
More file actions
97 lines (65 loc) · 2.12 KB
/
weekNine.js
File metadata and controls
97 lines (65 loc) · 2.12 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const dog = {
name: "Mango",
age: 3,
isGoodBoy: true,
};
console.log("dog", dog);
const json = JSON.stringify(dog);
console.log(json);
console.log(json[3]);
console.log(JSON.parse(json));
console.log("5")
console.log(JSON.parse("5"))
console.log("false");
console.log(JSON.parse("false"))
// const data = JSON.parse("Well, this is awkward");
// console.log(data);
try {
const data = JSON.parse("Well, this is awkward");
console.log(data);
} catch (error) {
console.log(error);
console.log(error.name); // "SyntaxError"
console.log(error.message); // Unexpected token W in JSON at position 0
}
console.log("✅ This is fine, we handled parsing error in try...catch");
// let veriler = []
// fetch('data.json')
// // .then(response => console.log(response))
// .then(response => response.json())
// .then(data => veriler.push(data))
// .catch(error => console.log(error))
// console.log(veriler);
window.navigator.geolocation.getCurrentPosition(position =>console.log(position))
function saveLocation() {
window.navigator.geolocation.getCurrentPosition(position => {
const lat = position.coords.latitude
const long = position.coords.longitude
document.cookie = `location=${lat},${long}; path=/`
})
}
saveLocation()
console.log(localStorage);
const settings = {
theme: "dark",
isAuthenticated: true,
options: [1, 2, 3],
};
localStorage.setItem("settings", JSON.stringify(settings));
console.log(JSON.parse(localStorage.getItem("settings")));
localStorage.removeItem("settings");
localStorage.setItem("ui-theme", "light");
// sessionStorage.setItem("user-id", "123");
const form = document.querySelector(".feedback-form");
const textarea = form.elements.message;
const localStorageKey = "goit-example-message";
textarea.value = localStorage.getItem(localStorageKey) ?? "";
form.addEventListener("input", (evt) => {
localStorage.setItem(localStorageKey, evt.target.value);
});
form.addEventListener("submit", (evt) => {
evt.preventDefault();
console.log(evt.target.elements.message.value);
localStorage.removeItem(localStorageKey);
form.reset();
});