요구조건

  1. 마우스가 title위로 올라가면 텍스트가 변경되어야 합니다.
  2. 마우스가 title을 벗어나면 텍스트가 변경되어야 합니다.
  3. 브라우저 창의 사이즈가 변하면 title이 바뀌어야 합니다.
  4. 마우스를 우 클릭하면 title이 바뀌어야 합니다.
  5. title의 색상은 colors 배열에 있는 색을 사용해야 합니다.
  6. 모든 함수 핸들러는 superEventHandler내부에 작성해야 합니다.
<!DOCTYPE html>
<html>
  <head>
    <title>Parcel Sandbox</title>
    <meta charset="UTF-8" />
  </head>

  <body>
    <h2>Hello!</h2>
    <script src="src/index.js"></script>
  </body>
</html>
// <⚠️ DONT DELETE THIS ⚠️>
import "./styles.css";
const colors = ["#1abc9c", "#3498db", "#9b59b6", "#f39c12", "#e74c3c"];
// <⚠️ /DONT DELETE THIS ⚠️>
const myText = document.querySelector("h2");

const superEventHandler = {
  click: function () {
    myText.innerText = "That was a right click!";
    myText.style.color = colors[0];
  },
  mouseEnter: function () {
    myText.innerText = "The mouse is here!";
    myText.style.color = colors[1];
  },
  mouseLeave: function () {
    myText.innerText = "The mouse is gone!";
    myText.style.color = colors[2];
  },
  resize: function () {
    myText.innerText = "You just Resized!";
    myText.style.color = colors[3];
  }
};

myText.addEventListener("contextmenu", superEventHandler.click);
myText.addEventListener("mouseenter", superEventHandler.mouseEnter);
myText.addEventListener("mouseleave", superEventHandler.mouseLeave);
window.addEventListener("resize", superEventHandler.resize);

 

 

[노마드코더] 바닐라JS 챌린지 - 마우스 이벤트, 윈도우 사이즈 - 글자 색변 경하기