THAPA TECHNICAL

HOUSE OF WEB DEVELOPERS AND TECHNOLOGY.

Reverse a String in JavaScript in RealTime without Reverse Function

Reverse a String in JavaScript in RealTime without Reverse Function

I know it's been a while I haven't uploaded any video in Advanced Tutorial in Javascript. But on the survey, I found that most of you are here for Javascript.


Below is the code for it.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Reverse</title>
</head>
<body>

<h2 style="text-align: center;">Reverse The String in Real Time with Decrementing For Loop.</h2>
<input type="text" name="" id="reversTheName" onkeyup="reverseString()">
<input type="text" name="" id="showData">

<script>
function reverseString(){
var str = document.getElementById('reversTheName').value;
var newString="";

for(var i=str.length-1; i>=0; i--){
newString += str[i];
}
document.getElementById('showData').value = newString;
}
</script>

</body>
</html>

No comments:

Post a Comment