Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
135
rated 0 times [  138] [ 3]  / answers: 1 / hits: 15481  / 11 Years ago, mon, november 11, 2013, 12:00:00

I want to reverse the stars from (smallest to biggest) to (Biggest to smallest)



  function seethestars1() {
for (var i = 0; i <= 10; i++) {
for (var j = 0; j < i; j++) {
document.getElementById(emptytext2).value += *;
}
document.getElementById(emptytext2).value += n;
}
}

<textarea id=emptytext2 name=S2>

<input id=emptytext3 type=button value=Click for the stars onclick =seethestars1() />

More From » html

 Answers
190

You can use it like this



for (var i = 10; i >= 0; i--) 


But I'm not sure why are you doing so because you are not using this variable inside your loop so I think it doesn't make any difference to the output as you loop going to run 10 times either way.



If I could guess then I think you want to print the stars in reverse order of quantity. That means you want to have maximum stars in first row then -1 in second and so on.. If so then you need to reverse the order of inner loop only like this



 function seethestars1() {
var stars = document.getElementById(emptytext2);
for (var i = 0; i <= 10; i++) {
for (var j = 10; j > i; j--) {
stars.value += *;
}
stars.value += n;
}
}


Js Fiddle Demo


[#74362] Saturday, November 9, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
keyonna

Total Points: 521
Total Questions: 104
Total Answers: 96

Location: Samoa
Member since Tue, May 3, 2022
2 Years ago
keyonna questions
;