Changing the last text of a loop
-
So right now my countdown loop goes "5,4,3,2,1," Is there a way to add something so that when it goes to 1 there is no more comma? Thank you! I am taking my first Javascript class so I apologize if my question is very basic.
-
So right now my countdown loop goes "5,4,3,2,1," Is there a way to add something so that when it goes to 1 there is no more comma? Thank you! I am taking my first Javascript class so I apologize if my question is very basic.
-
So right now my countdown loop goes "5,4,3,2,1," Is there a way to add something so that when it goes to 1 there is no more comma? Thank you! I am taking my first Javascript class so I apologize if my question is very basic.
You would have to show us the code you are currently using to do this. But my guess is you are just adding "," to some variable that is being decremented. So, just check if your variable is 1 first and if so, don't add the ","
There are only 10 types of people in the world, those who understand binary and those who don't.
-
So right now my countdown loop goes "5,4,3,2,1," Is there a way to add something so that when it goes to 1 there is no more comma? Thank you! I am taking my first Javascript class so I apologize if my question is very basic.
Hello, Just Check in Console it Works
var str,i,counter="";
for (i = 5 ; i >= 1; i--) {
str =i+',';
console.log(str);
counter+=str;
}
console.log(counter.replace(/.$/,""));
//console.log(counter.substring(0,counter.length-1));