So I’ve been trying to figure out how to assign the keyboard events of the numerical keys to emojis for this challenge. Not sure how to go about it.
and then display that rating in the form of an emoji. The users should give
their ratings by pressing a key on their keyboards (the numbers 1 to 5).
Here's the numbers' corresponding emojis:
5 = :grin:
3 = :slight_smile:
3 = :neutral_face:
2 = :frowning2:
1 = :face_with_symbols_over_mouth:
```event listeners, keyboard events, key codes,
focus, focusout, DOM manipulation, tabindex
*/
const box = document.getElementById("box")
const text = document.getElementById("text")
box.addEventListener("focus", function(){
text.textContent = "Type a number between 1 and 5"
})
box.addEventListener("focusout", function(){
text.textContent = "Click here to give your rating"
})
not sure if this is your typo or the prompts, but two of those number/emoji pairs say 3.
as for the question, you’ll need to use the keydown event listener and use the key codes for the number keys in question. you’ll need to check which key is being pressed and output the correct emoji depending on that key (i would use a switch statement).
it might look something like this:
box.addEventListener('keydown', event => {
switch(event) {
case (event.keyCode === 49): //keyCode for 1
return ':grin:';
break;
...
}
});
search “keydown value javascript” on google to find what key codes you need. good luck!