js/8/script2.js
2024-10-23 11:14:14 -05:00

26 lines
703 B
JavaScript

let wordList = document.querySelector("#word-list");
let sentence = document.querySelector("#sentence");
wordList.addEventListener("click", event => {
let word = event.target.textContent;
sentence.textContent += word;
sentence.textContent += " ";
});
let box = document.querySelector("#box");
let currentX = 0
let currentY = 0
document.querySelector("html").addEventListener("keydown", e => {
if (e.repeat === true){
return
} else if (e.key == "w") {
currentY -= 5;
} else if (e.key == "a") {
currentX -= 5;
} else if (e.key == "s") {
currentY += 5;
} else if (e.key == "d") {
currentX += 5;
}
box.style.left = currentX + "px";
box.style.top = currentY + "px";
});