⬛ Basic js console in js, jsception
✍ Practice JavaScript:
- Classes (definition, constructor, methods, composition)
- ES6 Modules (import, export)
Try executing this code in the jsconsole:
const consoleElement = document.querySelector('#console'); let {x, y} = consoleElement.getBoundingClientRect(); const updateConsolePosition = (x, y) => { consoleElement.style.top = `${y}px`; consoleElement.style.left = `${x}px` }; updateConsolePosition(x, y); consoleElement.style.position = "absolute"; const movementSpeed = 10; let key = ''; jsconsole.input.addEventListener("keydown", (e) => key = e.key); jsconsole.input.addEventListener("keyup", (e) => key = ""); setInterval(() => { switch(key) { case "w": { y -= movementSpeed; break; } case "s": { y += movementSpeed; break; } case "a": { x -= movementSpeed; break; } case "d": { x += movementSpeed; break; } default: break; } updateConsolePosition(x, y); }, 17); jsconsole.clear(); "Use the WASD keys to control the jsconsole!"