프로젝트 목적 : css,js에서 새롭게 배운 개념들을 활용하고 Open API를 사용해 현재 위치 날씨와 이미지를 받아오기
참여자 : ABlued
사용 스택 : HTML, CSS, JavaScript, JSON
작업 환경 : VSCode
-
CSS
- import, flex, 가상 선택자
-
JavaScript
- DON, Json 데이터 받아오기, Open API, 위도경도 계산
코드 위치 : js->weather.js 7번째 줄에 위치
function getWeather(coords) {
fetch(
`${WEATHER_API}lat=${coords.lat}&lon=${
coords.lng
}&appid=${API_KEY}&units=metric`
)
.then(response => response.json())
.then(json => {
const name = json.name;
const temperature = json.main.temp;
weather.innerHTML = `${Math.floor(temperature)}° @ ${name}`;
});
}
function handleGeoSuccess(position) {
const lat = position.coords.latitude;
const lng = position.coords.longitude;
const coords = {
lat,
lng
};
localStorage.setItem("coords", JSON.stringify(coords));
getWeather(coords);
}
코드 위치 : js -> todo.js 33번째 줄에 위치
function handleDelete(event) { //투두리스트 엘리멘트를 삭제
const target = event.target;
const li = target.parentElement;
const ul = li.parentElement;
const toDoId = li.id;
ul.removeChild(li);
toDos = toDos.filter(function(toDo) {
return toDo.id !== parseInt(toDoId);
});
persistToDos();
}
function addToDo(text) { // 투두리스트 엘리멘트를 추가
const toDo = document.createElement("li");
toDo.className = "toDo";
toDo.id = toDos.length + 1;
const deleteBtn = document.createElement("span");
deleteBtn.innerHTML = "❌";
deleteBtn.className = "toDo__button";
deleteBtn.addEventListener("click", handleDelete);
const label = document.createElement("label");
label.innerHTML = text;
toDo.appendChild(deleteBtn);
toDo.appendChild(label);
list.appendChild(toDo);
saveToDo(text);
}