Sunday, November 22, 2015

Ordinal Number Generator in JavaScript

A program that I wrote in JavaScript that will generate ordinal numbers based on the number given by the user.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

<html>
 <head>
<title> Ordinal Number Generator in JavaScript </title>
<style>
body {
    font-family:arial;
size:12;
}
</style>
</head>
<body>
<h3 align="center"> Ordinal Number Generator in JavaScript </h3>
<script>

function ordinal(num_values) {
   var str_values=["th","st","nd","rd"];
       values=num_values%100;
   return num_values+(str_values[(values-20)%10]||str_values[values]||str_values[0]);
}
   
var number = parseInt(prompt("Enter a number"));
var a;

for (a=1; a<=number; a++)
{
document.write("<font face='arial' size='4'>");
document.write("&nbsp;" +ordinal(a) + " </font>");
}
</script>
</body>
</html>



No comments:

Post a Comment