조건
Use if/else etc.
Links
Window
resize 해줄 때마다 window의 색이 바뀌게 하는 것
너비값을 변수로 지정해주기위해 무슨 메소드를 써야하는지 구글링.
javascript에서 background-color를 불러오기 위해서는 object.style.backgroundColor(Camel Type)을 쓰면 된다
if와 else if 식을 써줄 때 소괄호와 중괄호를 한번에, 깔끔하게 쓰는 연습을 하자.
if (condition) {
} else if (condition) {
} else {
};
ANSWER1
ANSWER2
*classList 내장함수를 사용하여 클래스와 그에 연결된 class값들을 연결하여 불러오기
<!DOCTYPE html>
<html>
<head>
<title>Parcel Sandbox</title>
<meta charset="UTF-8" />
</head>
<body class="mediumScreen">
<h2>Hello!</h2>
<script src="src/index.js"></script>
</body>
</html>
body {
font-family: sans-serif;
display: flex;
}
h2 {
color: white;
}
.bigScreen {
background-color: #f1c40f;
}
.mediumScreen {
background-color: #9b59b6;
}
.smallScreen {
background-color: #3498db;
}
import "./styles.css";
const body = document.body;
const BIG_SCREEN = "bigScreen";
const MEDIUM_SCREEN = "mediumScreen";
const SMALL_SCREEN = "smallScreen";
function handleResize() {
const width = window.innerWidth;
if (width > 1000) {
body.classList.add(BIG_SCREEN);
body.classList.remove(MEDIUM_SCREEN);
} else if (width <= 1140 && width >= 700) {
body.classList.add(MEDIUM_SCREEN);
body.classList.remove(BIG_SCREEN, SMALL_SCREEN);
} else {
body.classList.remove(MEDIUM_SCREEN);
body.classList.add(SMALL_SCREEN);
}
}
window.addEventListener("resize", handleResize);
make an app that shows the time until Christmas Eve in days, hours, minutes and seconds.
조건
Find a random number on a range between 0 and a number defined by the user.
Use range input.
Update the range value in real time.
Only play after the user chooses a number.
Notify the user if the game is lost or won.
oninput event
Execute a JavaScript when a user writes something in an <input>
field:
object.oninput = function(){myScript};
In JavaScript, using the addEventListener() method:
object.addEventListener("input", myScript);
range.addEventListener("input", handleValue);라고 했어도 It works!