I'm trying to have each key, correspond to different images when pressed. (Ex: When "A" is pressed = image1 appears, When "S" is pressed = image2 appears, and so on.)
I was able to get the "S" Key to work, but not the A. I'm trying to do this for the whole row on the keyboard ("A","S","D","F","G","H","J","K","L")
*PS. Im still a beginner :)
This is my code:
<img src="images/giphy.gif" width="800" height="400" alt=""/>
<script>
document.addEventListener("keydown", keyDownBody, false);
function keyDownBody(e) {
var keyCode = e.keyCode;
if(keyCode==65) {
myFunction();
}
}
function myFunction() {
var x = document.createElement("IMG");
x.setAttribute("src", "images/giphy1.gif")
x.setAttribute("width", "800");
x.setAttribute("height", "400");
x.setAttribute("alt", "The Pulpit Rock");
document.body.appendChild(x);
}
function keyDownBody(e) {
var keyCode = e.keyCode;
if(keyCode==83) {
myFunction();
}
}
function myFunction() {
var x = document.createElement("IMG");
x.setAttribute("src", "images/sun.gif")
x.setAttribute("width", "800");
x.setAttribute("height", "400");
x.setAttribute("alt", "The Pulpit Rock");
document.body.appendChild(x);
}
</script>