I recently finished my Valentines mini-project. I made it sort of problem-solvey and it was fun to do and make!
In Class Activity:
Create div
Style Div
Add an eventlistener for a keypress
If statement for the keypress of the button you want
For each keypress, increase div's position by an interval
Here is the annotated code:
buggy.style.left = "0px";
var x = parseInt(buggy.style.left);
Retrive only an integer value, excluding the "px" and setting that to a variable. This variable represents the div's position.
document.addEventListener("keydown", function(event){
console.log(x)
x = x+10; variable increases for every keydown
buggy.style.left = x +"px"; Since the variable increases, the div's position also increases/goes to the left more.
})