programming-examples/js/Array/Write a JavaScript program to display the colors in the following way.js
2019-11-15 12:59:38 +01:00

16 lines
385 B
JavaScript

var color = ["Blue ", "Green", "Red", "Orange", "Violet", "Indigo", "Yellow "];
function Ordinal(n)
{
var o = ["th","st","nd","rd"],
x = n%100;
return x+(o[(x-20)%10]||o[x]||o[0]);
}
for(n = 0; n < color.length; n++){
var ordinal = n + 1;
var output = (Ordinal(ordinal) + " choice is " + color[n] + ".");
console.log(output);
}