๐ŸŽˆ๋…ธ๋งˆ๋“œ์ฝ”๋” ํฌ๋กฌ์•ฑ ๋งŒ๋“ค๊ธฐ๐ŸŽˆ

๐ŸŽˆ๋…ธ๋งˆ๋“œ์ฝ”๋” ํฌ๋กฌ์•ฑ ๋งŒ๋“ค๊ธฐ๐ŸŽˆ


๐Ÿ“Œ๊ณ„๊ธฐ

์นœ๊ตฌ์™€ ํ† ์ดํ”„๋กœ์ ํŠธ๋ฅผ ๊ฐ€๋ณ๊ฒŒ ์ง„ํ–‰์ค‘์ธ๋ฐ, ํ”„๋ก ํŠธ์—”๋“œ์˜ ์Šคํƒ์„ ๋ฆฌ์•กํŠธ๋กœ ์‚ฌ์šฉํ•ด์•ผ๊ฒ ๋‹ค~ ๊ฒฐ์ •ํ–ˆ์ง€๋งŒ ์›น์€ ์ •๋ง ์ฒ˜์Œ์ด๋ผโ€ฆ ๊ธฐ์ดˆ๋Š” ํ•˜๊ณ  ๊ฐ€์•ผ๊ฒ ๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค๐Ÿ˜‚
๋ฐ”๋กœ ๋ฆฌ์•กํŠธ๋ฅผ ๊ณต๋ถ€ํ•˜๋ฉด์„œ ํ•ด๋ดค๋Š”๋ฐ, ๊ตฌ๋ฆ„์œ„์—์„œ ์ฝ”๋”ฉํ•˜๋Š” ๋“ฏ์ด(โ€ฆ) ๋ญ๊ฐ€๋ญ”์ง€ ์ž˜ ๋ชจ๋ฅด๊ฒ ์–ด์„œ ์ฐจ๊ทผ์ฐจ๊ทผ ํ•˜๋Š” ๊ฒƒ์— ๋Œ€ํ•œ ์ค‘์š”์„ฑ์„ ๊นจ๋‹ฌ์•˜์Šต๋‹ˆ๋‹ค๐Ÿคฃ
ํ•ด์„œ ์„ ํƒํ•œ ๊ฒƒ์ด ๋…ธ๋งˆ๋“œ์ฝ”๋” ํฌ๋กฌ์•ฑ ๊ฐ•์˜! ์˜€๋Š”๋ฐ, ๋“ค์–ด๋ณด๋‹ˆ๊นŒ ํ™•์‹คํžˆ ๋ญ ์–ด๋–ป๊ฒŒ ํ•ด์•ผํ• ์ง€ ๊ฐ์ด ์žกํžˆ๋Š” ๋Š๋‚Œ์ด์—ˆ๋„ค์š”!๐Ÿ˜†๐Ÿ˜†

์ด์ œ ๋ฐ”๋‹๋ผ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ด์šฉํ•ด ํ† ์ดํ”„๋กœ์ ํŠธ 2๊ฐœ ์ •๋„๋ฅผ ์ง์ ‘ ์ง„ํ–‰ํ•ด๋ณด๊ณ  ๋ฆฌ์•กํŠธ๋กœ ๋„˜์–ด๊ฐ€๋ คํ•ฉ๋‹ˆ๋‹ค.


๐Ÿ“Œ์ฝ”๋“œ

๐Ÿ“„ index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="css/style.css" />
    <title>Momentum App</title>
  </head>
  <body>
    <div id="weather">
      <span class="weat"></span>
      <span class="home"></span>
    </div>
    <h2 id="clock">00:00:00</h2>
    <form class="hidden" id="login-form">
      <input
        required
        maxlength="15"
        type="text"
        placeholder="What is your name?"
      />
      <button>Log In</button>
    </form>
    <h1 id="greeting" class="hidden"></h1>
    <form id="todo-form">
      <input type="text" placeholder="Write a To Do" required />
    </form>
    <ul id="todo-list"></ul>
    <div id="quote">
      <span></span><br />
      <span></span>
    </div>
    <script src="js/greetings.js"></script>
    <script src="js/clock.js"></script>
    <script src="js/quotes.js"></script>
    <script src="js/background.js"></script>
    <script src="js/todo.js"></script>
    <script src="js/secret.js"></script>
    <script src="js/weather.js"></script>
  </body>
</html>

๐Ÿ“„ greeting.js

const loginForm = document.querySelector("#login-form");
const loginInput = document.querySelector("#login-form input");
const greeting = document.querySelector("#greeting");
const HIDDEN_CLASSNAME = "hidden";
const USERNAME_KEY = "username";

function onLoginSubmit(event) {
  event.preventDefault();
  loginForm.classList.add(HIDDEN_CLASSNAME);
  localStorage.setItem(USERNAME_KEY, loginInput.value);
  paintGreetings();
}

function paintGreetings() {
  const username = localStorage.getItem(USERNAME_KEY);
  greeting.innerText = `Hello ${username}`;
  greeting.classList.remove(HIDDEN_CLASSNAME);
}

const savedUsername = localStorage.getItem(USERNAME_KEY);

console.log(savedUsername);

if (savedUsername === null) {
  loginForm.classList.remove(HIDDEN_CLASSNAME);
  loginForm.addEventListener("submit", onLoginSubmit);
} else {
  paintGreetings();
}

๐Ÿ“„ quotes.js

const quotes = [
  {
    quote: "I never dreamed about success, I worked for it.",
    author: "Estee Lauder",
  },
  {
    quote: "Do not try to be original, just try to be good.",
    author: "Paul Rand",
  },
  {
    quote: "Do not be afraid to give up the good to go for the great.",
    author: "John D. Rockefeller",
  },
  {
    quote:
      "If you cannot fly then run. If you cannot run, then walk. And, if you cannot walk, then crawl, but whatever you do, you have to keep moving forward.",
    author: "Martin Luther King Jr.",
  },
  {
    quote:
      "Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time.",
    author: "Thomas Edison",
  },
  {
    quote:
      "The fastest way to change yourself is to hang out with people who are already the way you want to be.",
    author: "Reid Hoffman",
  },
  {
    quote:
      "Money is like gasoline during a road trip. You do not want to run out of gas on your trip, but you 're not doing a tour of gas stations.",
    author: "Tim O'Reilly",
  },
  {
    quote:
      "Some people dream of success, while other people get up every morning and make it happen.",
    author: "Wayne Huizenga",
  },
  {
    quote:
      "The only thing worse than starting something and failing ... is not starting something.",
    author: "Seth Godin",
  },
  {
    quote:
      "If you really want to do something, you'll find a way. If you do not, you'll find an excuse.",
    author: "Jim Rohn",
  },
];

const quote = document.querySelector("#quote span:first-child");
const author = document.querySelector("#quote span:last-child");

const todaysQuote = quotes[Math.floor(Math.random() * quotes.length)];

quote.innerText = todaysQuote.quote;
author.innerText = todaysQuote.author;

๐Ÿ“„ background.js

const images = ["0.jpg", "1.jpg", "2.jpg", "3.jpg"];

const chosenImage = images[Math.floor(Math.random() * images.length)];

const bgImage = document.createElement("img");

bgImage.src = `img/${chosenImage}`;
bgImage.classList.add("bgImage");

document.body.appendChild(bgImage);

๐Ÿ“„ todo.js

const toDoForm = document.querySelector("#todo-form");
const toDoInput = toDoForm.querySelector("input"); //document.querySelector("#todo-iform input");
const toDoList = document.querySelector("#todo-list");

const TODOS_KEY = "todos";
let toDos = [];

function saveToDos() {
  localStorage.setItem(TODOS_KEY, JSON.stringify(toDos));
}

function deleteToDo(event) {
  const li = event.target.parentElement;
  li.remove();
  toDos = toDos.filter((toDo) => toDo.id !== parseInt(li.id));
  saveToDos();
}

function paintToDo(newTodo) {
  const li = document.createElement("li");
  li.id = newTodo.id;
  const span = document.createElement("span");
  span.innerText = newTodo.text;
  const button = document.createElement("button");
  button.innerText = "โŒ";
  button.addEventListener("click", deleteToDo);
  li.appendChild(span);
  li.appendChild(button);
  toDoList.appendChild(li);
}

function handleToDoSubmit(event) {
  event.preventDefault();
  const newTodo = toDoInput.value;
  toDoInput.value = "";
  const newTodoObj = {
    text: newTodo,
    id: Date.now(),
  };
  toDos.push(newTodoObj);
  paintToDo(newTodoObj);
  saveToDos();
}

toDoForm.addEventListener("submit", handleToDoSubmit);

const savedToDos = localStorage.getItem(TODOS_KEY);

if (savedToDos) {
  const parsedToDos = JSON.parse(savedToDos);
  toDos = parsedToDos;
  parsedToDos.forEach(paintToDo);
}

๐Ÿ“„ weather.js

function onGeoOk(position) {
  const lat = position.coords.latitude;
  const lon = position.coords.longitude;
  console.log("You live it", lat, lon);
  const url = `https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&appid=${API_KEY}&units=metric`;
  fetch(url)
    .then((response) => response.json())
    .then((data) => {
      const weather = document.querySelector("#weather span:first-child");
      const city = document.querySelector("#weather span:last-child");
      city.innerText = data.name;
      weather.innerText = data.weather[0].main;
    });
}
function onGeoError() {
  alert("Can't find you. No weather for you.");
}

navigator.geolocation.getCurrentPosition(onGeoOk, onGeoError);

๐Ÿ“„ style.css

.hidden {
  display: none;
}

body {
  background-color: #2d3436;
  text-align: center;
  color: #ecf0f1;
  padding: 1%;
}

h2 {
  font-size: 5rem;
  margin-top: 8%;
}

h1 {
  font-size: 3rem;
  font-style: italic;
}

input {
  border: none;
  background: transparent;
  font-size: 20px;
  margin: 3px;
  text-align: center;
  color: #ecf0f1;
  border-bottom: 2px solid #ecf0f1;
}

button {
  border: none;
  background: transparent;
  font-size: 22px;
}

ul {
  margin-left: 42%;
}

li {
  list-style: none;
  font-size: 20px;
  text-align: left;
  color: #ecf0f1;
}

li:before {
  content: "๐Ÿ’˜";
  display: inline;
  vertical-align: left;
  padding: 5px;
}

.bgImage {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  animation: fadeIn 0.5s linear;
}

.weat {
  padding-left: 90%;
}

.home {
  padding-left: 90%;
}

๐Ÿ“Œ์™„์„ฑ

์˜ˆ์ฉ๋‹ˆ๋‹ค!


๐Ÿ“Œํ›„๊ธฐ

๊ฐ•์˜๋ฅผ ๋“ค์œผ๋ฉด์„œ ๋” ๊นŠ๊ฒŒ ๊ณต๋ถ€ํ•ด์•ผํ•  ๊ฒƒ์ด๋‚˜, ์ค‘์š”ํ•˜๋‹ค๊ณ  ์ƒ๊ฐ์ด ๋“œ๋Š” ๋ถ€๋ถ„์€ ๋”ฐ๋กœ ๋ฉ”๋ชจ๋ฅผํ–ˆ์Šต๋‹ˆ๋‹ค.
๋„ˆ๋ฌด ์ฃผ์ ˆ์ฃผ์ ˆ ์ €๋งŒ ์•Œ์•„ ๋ณผ ์ˆ˜ ์žˆ๊ฒŒ ์ •๋ฆฌํ•ด์„œ ๋ฐ”๋กœ ์—…๋กœ๋“œ ํ•˜๊ธด ์–ด๋ ต๊ฒ ์ง€๋งŒ ์ฒœ์ฒœํžˆ ๋ณต์Šตํ•˜๊ณ  ์˜ˆ์˜๊ฒŒ ํฌ์ŠคํŒ… ํ•ด๋ณผ ์ƒ๊ฐ์ž…๋‹ˆ๋‹ค.

์ƒ๊ฐ๋ณด๋‹ค ๋„ˆ๋ฌด ์žฌ๋ฐŒ๋Š” ๊ฐ•์˜์˜€๊ณ , HTML CSS JS ๋ชจ๋‘ ์ฒ˜์Œ์ด๊ธด ํ•˜์ง€๋งŒ ๋ฆฌ์•กํŠธ๋ฅผ ๋งŒ์ง€๋ฉด์„œ ๋Œ€~์ถฉ ์•Œ๊ณ  ์žˆ๋Š” ๊ฒƒ์ด ์žˆ์–ด์„œ ๊ทธ๋Ÿฐ๊ฐ€ ์–ด๋ ค์›Œ์„œ ๋‹ค์‹œ๋“ค์–ด๋ณด๊ฑฐ๋‚˜ ํ•˜๋Š” ๊ฑด ์—†์—ˆ์–ด์š”!

์ด์ œ ๊ฐ•์˜์—์„œ ๋ฐฐ์šด ๊ฒƒ์„ ํ† ๋Œ€๋กœ ์ƒˆ๋กœ์šด ์›น ์•ฑ์„ ์ œ์ž‘ํ•ด๋ณผ ์ƒ๊ฐ์ž…๋‹ˆ๋‹ค!

  • ํ•˜๋ฃจ ํ•œ ์ค„ ์ผ๊ธฐ
  • ๋‚˜๋งŒ์˜ ๋•์งˆ ํŽ˜์ด์ง€

์ด๋ฒˆ์ฃผ์•ˆ์— ์™„์„ฑํ•˜๋Š”๊ฒŒ ๋ชฉํ‘œ์ž…๋‹ˆ๋‹ค๐Ÿ˜Œ
ํ™”์ดํŒ…๐Ÿคธโ€โ™€๏ธ๐Ÿคธโ€โ™€๏ธ

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ