├── .gitignore ├── css └── style.css ├── img ├── 0.jpeg ├── 1.jpeg └── 2.jpeg ├── README.md ├── js ├── background.js ├── clock.js ├── weather.js ├── greetings.js ├── quotes.js └── todo.js └── index.html /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store -------------------------------------------------------------------------------- /css/style.css: -------------------------------------------------------------------------------- 1 | .hidden { 2 | display: none; 3 | } 4 | -------------------------------------------------------------------------------- /img/0.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomadcoders/javascript-for-beginners/HEAD/img/0.jpeg -------------------------------------------------------------------------------- /img/1.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomadcoders/javascript-for-beginners/HEAD/img/1.jpeg -------------------------------------------------------------------------------- /img/2.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nomadcoders/javascript-for-beginners/HEAD/img/2.jpeg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Javascript For Beginners 2 | 3 | Learning Javascript by Making a Productivity App 4 | -------------------------------------------------------------------------------- /js/background.js: -------------------------------------------------------------------------------- 1 | const images = ["0.jpeg", "1.jpeg", "2.jpeg"]; 2 | 3 | const chosenImage = images[Math.floor(Math.random() * images.length)]; 4 | 5 | const bgImage = document.createElement("img"); 6 | 7 | bgImage.src = `img/${chosenImage}`; 8 | 9 | document.body.appendChild(bgImage); 10 | -------------------------------------------------------------------------------- /js/clock.js: -------------------------------------------------------------------------------- 1 | const clock = document.querySelector("h2#clock"); 2 | 3 | function getClock() { 4 | const date = new Date(); 5 | const hours = String(date.getHours()).padStart(2, "0"); 6 | const minutes = String(date.getMinutes()).padStart(2, "0"); 7 | const seconds = String(date.getSeconds()).padStart(2, "0"); 8 | clock.innerText = `${hours}:${minutes}:${seconds}`; 9 | } 10 | 11 | getClock(); 12 | setInterval(getClock, 1000); 13 | -------------------------------------------------------------------------------- /js/weather.js: -------------------------------------------------------------------------------- 1 | const weather = document.querySelector("#weather span:first-child"); 2 | const city = document.querySelector("#weather span:last-child"); 3 | const API_KEY = "241051bf13976dd3ddf8b8d9f247255e"; 4 | 5 | function onGeoOk(position) { 6 | const lat = position.coords.latitude; 7 | const lon = position.coords.longitude; 8 | const url = `https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&appid=${API_KEY}&units=metric`; 9 | fetch(url) 10 | .then((response) => response.json()) 11 | .then((data) => { 12 | city.innerText = data.name; 13 | weather.innerText = `${data.weather[0].main} / ${data.main.temp}`; 14 | }); 15 | } 16 | function onGeoError() { 17 | alert("Can't find you. No weather for you."); 18 | } 19 | 20 | navigator.geolocation.getCurrentPosition(onGeoOk, onGeoError); 21 | -------------------------------------------------------------------------------- /js/greetings.js: -------------------------------------------------------------------------------- 1 | const loginForm = document.querySelector("#login-form"); 2 | const loginInput = document.querySelector("#login-form input"); 3 | const greeting = document.querySelector("#greeting"); 4 | 5 | const HIDDEN_CLASSNAME = "hidden"; 6 | const USERNAME_KEY = "username"; 7 | 8 | function onLoginSubmit(event) { 9 | event.preventDefault(); 10 | loginForm.classList.add(HIDDEN_CLASSNAME); 11 | const username = loginInput.value; 12 | localStorage.setItem(USERNAME_KEY, username); 13 | paintGreetings(username); 14 | } 15 | 16 | function paintGreetings(username) { 17 | greeting.innerText = `Hello ${username}`; 18 | greeting.classList.remove(HIDDEN_CLASSNAME); 19 | } 20 | 21 | const savedUsername = localStorage.getItem(USERNAME_KEY); 22 | 23 | if (savedUsername === null) { 24 | loginForm.classList.remove(HIDDEN_CLASSNAME); 25 | loginForm.addEventListener("submit", onLoginSubmit); 26 | } else { 27 | paintGreetings(savedUsername); 28 | } 29 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 |