Write a Javascript Program in AI
💡
The code produced is as follows (requires verification for accuracy):
function reverseWord() {
// Ask the user for a word
var word = prompt("Please enter a word:");
// Reverse the word
var reversedWord = "";
for (var i = word.length - 1; i >= 0; i--) {
reversedWord += word[i];
}
// Display the reversed word
alert(reversedWord);
}
// Call the function
reverseWord();
This code defines a function called reverseWord() that asks the user for a word using the prompt function, and then reverses the word using a loop. Finally, it displays the reversed word using the alert function.