0

I'm new to javascript and I need help. I'm currently doing a project using javascript in which I'm tasked with creating some code which asks the user to hit any key to exit the javascript program. does anybody know how I can do this?

I've tried using the addeventlistener to detect user input but it doesn't seem to work for me.

Edit: I’m supposed to ask the user to input any key to exit the JavaScript program after it translates a number to the chosen language.

  • Hi, can you share the code you tried? – Jonathan DS Jan 27 '23 at 12:22
  • I've tried something like this but I think it doesn't seem to work. // Add event listener on keydown document.addEventListener('keydown', (event) => { var name = event.key; var code = event.code; // Alert the key name and key code on keydown alert(`Key pressed ${name} \r\n Key code value: ${code}`); }, false); – andrew acevedo Jan 27 '23 at 23:38
  • Please provide enough code so others can better understand or reproduce the problem. – Ralle Mc Black Jan 28 '23 at 00:55
  • this is part of my code, where should I place the hit any key to exit? const language = prompt("Choose a language - german or french"); console.log(language); if(language === "french") { return ("Your french translation is: "+germanTranslation[yournumber]); } else if(language === "german") { return("Your german translation is: "+germanTranslation[yournumber]); } else { alert("Please enter a valid language(german or french)."); return; } } //This calls the translate function. translate(); //End of the code. – andrew acevedo Jan 28 '23 at 01:14

0 Answers0