728x90
<html>
<head>
<title>Challenge 16</title>
<body bgcolor=black onload=kk(1,1) onkeypress=mv(event.keyCode)>
<font color=silver id=c></font>
<font color=yellow size=100 style=position:relative id=star>*</font>
<script>
document.body.innerHTML+="<font color=yellow id=aa style=position:relative;left:0;top:0>*</font>";
function mv(cd){
kk(star.style.left-50,star.style.top-50);
if(cd==100) star.style.left=parseInt(star.style.left+0,10)+50+"px";
if(cd==97) star.style.left=parseInt(star.style.left+0,10)-50+"px";
if(cd==119) star.style.top=parseInt(star.style.top+0,10)-50+"px";
if(cd==115) star.style.top=parseInt(star.style.top+0,10)+50+"px";
if(cd==124) location.href=String.fromCharCode(cd)+".php"; // do it!
}
function kk(x,y){
rndc=Math.floor(Math.random()*9000000);
document.body.innerHTML+="<font color=#"+rndc+" id=aa style=position:relative;left:"+x+";top:"+y+" onmouseover=this.innerHTML=''>*</font>";
}
</script>
</body>
</html>
body 태그를 보면 onkeypress="mv(event.keyCode)" 가 있다.
onkeypress는 키 입력을 감지한다. 내가 입력한 키 값이 mv 함수의 인자로 전달된다.
100, 97, 119, 115에 해당하는 문자는 각각 d, a, w, s이다. 화면에서 w, a, s, d를 각각 눌러보면 노란 별이 움직이는 것을 확인할 수 있다. 코드를 보면 star.style.left 또는 top의 값이 변하기 때문이다.
124에 해당하는 문자(|)를 입력하면 문제가 풀린다.
개발자 옵션에서 콘솔 창에 mv(124)를 입력해도 풀 수 있다.
728x90