- Joined
- Aug 31, 2022
- Messages
- 8
- Reaction score
- 0
I'm new to programming and I've read and watched several resources about for, while loops, but everytime I write the while loop to reverse the output from the for loop, the code doesn't run properly. I'm sort of just guessing at this point.
Does anyone know of a good article/video to better understand reversing the output from user input by using a while loop?
I commented out the while loop I was working on.
Does anyone know of a good article/video to better understand reversing the output from user input by using a while loop?
I commented out the while loop I was working on.
HTML:
<html>
<body style="text-align:center;">
<h1>Enter Your Five Favorite Cities</h1>
<form class="" action="index.html">
<input type="text" name="favoriteCities[]" value="" /><br>
<br>
<input type="text" name="favoriteCities[]" value="" /><br>
<br>
<input type="text" name="favoriteCities[]" value="" /><br>
<br>
<input type="text" name="favoriteCities[]" value="" /><br>
<br>
<input type="text" name="favoriteCities[]" value="" /><br>
<br>
<button type="button" name="button" onclick="favoriteCities()">Submit</button>
</form>
<h2>Results</h2>
<p id="output"></p>
<script type="text/javascript">
var r = "";
function favoriteCities() {
var input = document.getElementsByName('favoriteCities[]');
for (var i = 0; i < input.length; i++) {
var a = input[i]; var uniqueNumber=i+1;
r = r + "City #" + uniqueNumber + " is " + a.value + ("<br>");
}
document.getElementById("output").innerHTML = r;
//while (4 = input.length) {
//print (output)
//}
}
</script>
</body>
</html>