1/15
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
Function of AreaOfCircle to accept the radius of a circle & calculate the area of the circle.
function AreaOfCircle(r) {
return Math.PI * (r * r);
}
Function called YearCalculator to accept birthday in format (mm/dd/yyyy) and return the year.
function YearCalculator(birthday) {
var bday = birthday.split("/");
return bday[2];
}
Function called AgeCalculator to accept birthday in format (mm/dd/yyyy) and return the age.
function AgeCalculator(birthday) {
var today = new Date( );
var birthDate = new Date (birthday);
var age = today.getFullYear( ) - birthDate.getFullYear( );
var m = today.getMonth( ) - birthDate.getMonth( );
if (m < 0 || (m === 0 && today.getDate( ) < birthDate.getDate( ) ) ) {
age--;
}
return age;
}
Function BDYearCalculator to accept age and return the birthday year.
function BDYearCalculator(age) {
var today = new Date( );
return (today.getFullYear( ) - age);
}
Function Greeting to accept name and return the greeting to the user
function Greeting(name) {
return var greeting = " Hi " + name + " Welcome to the website.";
}
Function RandomGenerator to accept two integers and return a random integer between these numbers.
function RandomGenerator(a,b) {
return Math.floor(a + Math.random( )*(b-a) );
}
Function FourDigitRandomGenerator to return a 4-digit random integer.
function FourDigitRandomGenerator( ) {
return Math.floor(1000 + Math.random( )*8999);
}
Function FourCharRandomGenerator to return a 4-character random string
function FourCharRandomGenerator( ) {
var Chrs = "abcdefghijklmnopqrstuvwxyz";
var random string = "";
var j;
for (var i = 0; i < 4; i++) {
j = Math.floor(Math.random( ) * 25);
randomstring += Chrs.charAt(j);
}
return randomstring;
Function FourCharRandomGenerator to return a 4-character random string. Characters are limited to a,d,f,h,u,r,w.
function FourCharRandomGenerator( ) {
var Chrs = "adfhurw";
var random string = "";
var j;
for (var i = 0; i < 4; i++) {
j = Math.floor(Math.random( ) * 6);
randomstring += Chrs.charAt(j);
}
return randomstring;
Function OddNumbers to accept two integers a and b and return an array including odd numbers between a and b.
function OddNumbers(a, b) {
var OddNum = new Array( );
var j = 0;
for (var i = a; i < (b + 1); i++) {
if ((i % 2) != 0) {
OddNum[j] = i;
j++;
}
}
return OddNum;
}
OUTCOME
7,9,11,13,15,17,19,21,23
Function MultiplesFive to accept two integers a and b and return an array including all of the multiples of 5 between a and b.
function OddNumbers(a, b) {
var OddNum = new Array( );
var j = 0;
for (var i = a; i < (b + 1); i++) {
if ((i % 5) == 0) {
OddNum[j] = i;
j++;
}
}
return OddNum;
}
OUTCOME
10,15,20,25,30,35,40,45,50,55,60,65.........120
Function TimeTable to return a 10 by 10 times table in 10 rows and 10 columns
function TimesTable(rows, cols) {
vat TT = new Array( );
rows = 11;
cols = 11;
var TT = new Array( );
for (i = 1; i < rows; i++) {
TT [i] = new Array( );
for (j = 1; j < cols; j++) {
T T[i][j] = i * j;
document.write(T T[i][j] + " ");
}
document.write("
");
}
}
Function RandomColor to return a random color from an array including 10 different colors.
function randomcolor( ) {
colors=["black", "blue", "white", "red", "yellow", "orange", "purple", "violet", "gray", "brown"]
return colors[math.floor(Math.random( ) *10)];
}
Function RandomColorAndFlower to return a random color from an array including 10 different colors and a random flower from an array including 5 different flowers.
function MonthName(MonthValue) {
Month_Name = ["January", "February", "march", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
return Month_Name[MonthValue];
}
Function MonthName to accept Month value and return the Month name.
var monthNames = ["January", "February", "march", "April", "May", "June", "July", "August", "September", "October", "November", "December"
];
var d = new Date( );
document.write("The current month is " + monthNames[d.getMonth( )]);
Function FavoriteColors to ask user (using prompt method) to enter 3 colors separated with"," and return an array including the entered colors.
var colors = prompt("Please enter your three favorite colors. Use the format shown below.","Red, Green, Blue");
var uColors = colors.split(", ");
uColors = colors.split(", ");
user.favoriteColors.color1 = uColors[0];
user.favoriteColors.color2 = uColors[1];
user.favoriteColors.color3 = uColors[2];
while (colors.indexOf(", ") == -1 || colors == "" || uColors[0] == "" || uColors[1] == "" || uColors[2] == ""){
alert("Please correct your color format.");
colors = prompt("Please enter your three favorite colors. Use the format shown below.","Red, Green, Blue");
uColors = colors.split(",");
user.favoriteColors.color1 = uColors[0];
user.favoriteColors.color2 = uColors[1];
user.favoriteColors.color3 = uColors[2];
}
document.writeln("Favorite Colors: " + "" + user.favoriteColors.color1 + "" + user.favoriteColors.color2 + "" + user.favoriteColors.color3 + "
");