Created
July 17, 2019 12:03
-
-
Save ibare/705022ced9dbfc7817f17c5848b50133 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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