Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. var colors = ["Purple","Blue","Grey","Black","Green"];
  2.  
  3. function loop(x) {
  4. for(i=0; i<x.length; i++) {
  5. num = i + 1;
  6. suf = "";
  7. if (num == 1){
  8. suf = "st";
  9. }
  10. else if (num == 2){
  11. suf = "nd"
  12. }
  13. else if (num == 3){
  14. suf = "rd"
  15. }
  16. else {
  17. suf = "th"
  18. }
  19. ans = "My " + num + suf +" color is " + x[i];
  20. console.log(ans);
  21. }
  22. }
  23.  
  24. loop(colors);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement