Skip to content

Instantly share code, notes, and snippets.

@ibare
Created July 17, 2019 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ibare/705022ced9dbfc7817f17c5848b50133 to your computer and use it in GitHub Desktop.
Save ibare/705022ced9dbfc7817f17c5848b50133 to your computer and use it in GitHub Desktop.
function random(max) {
return Math.floor(Math.random()*max);
}
const startButton = document.querySelector('#start');
const boxes = [
document.querySelector('#b1'),
document.querySelector('#b2'),
document.querySelector('#b3')
];
function checkAnswer() {
alert('정답입니다')
}
startButton.addEventListener('click', function() {
// 이 곳에서 하나만 색이 다른 상자를 만드는 로직을 작성합니다.
const dfColorIndex = random(3);
const baseColor = {
red: random(256),
green: random(256),
blue: random(256)
};
boxes[i].addEventListener('click', checkAnswer);
for(let i=0; i<=2; i++) {
if (i === dfColorIndex) {
boxes[i].style.backgroundColor = `rgb(${baseColor.red}, ${baseColor.green + 20}, ${baseColor.blue})`;
boxes[i].addEventListener('click', checkAnswer);
} else {
boxes[i].style.backgroundColor = `rgb(${baseColor.red}, ${baseColor.green}, ${baseColor.blue})`;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment