-3

This code reverses the string and I want to add "ay" at the end of the word.

var string = prompt("Enter string:");
var strLen = string.length;

for(var i = strLen-1; i >= 0; i--){
   document.writeln(string[i]);
} 
Jamiec
  • 133,658
  • 13
  • 134
  • 193
  • End of what word? Also [do not use `document.write` or `document.writeLn`](https://stackoverflow.com/questions/802854/why-is-document-write-considered-a-bad-practice) – evolutionxbox Mar 07 '22 at 13:00
  • @evolutionxbox May be end of each word)) Because if he want just add "ay" at the end of whole string then it is very strange question))) – EzioMercer Mar 07 '22 at 13:02
  • Does this answer your question [Split string into words in javascript](https://stackoverflow.com/questions/18927223/split-string-into-words-in-javascript) – evolutionxbox Mar 07 '22 at 13:03
  • You do not need a loop; you can handle everything with a simple RegExp and `String.prototype.replace()`: `const output = input.replace(/([A-Za-z]+)/gi, $1 => $1.split('').reverse().join('') + 'ay')` – secan Mar 07 '22 at 13:27

1 Answers1

-1

    var string = prompt("Enter string:");
    string = string.split("").reverse().join("");
    string += "ay";

    document.write(string)
Vugar Taghiyev
  • 413
  • 3
  • 9