COP 2500 Midterm Practice 1

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/15

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

16 Terms

1
New cards

Function of AreaOfCircle to accept the radius of a circle & calculate the area of the circle.

function AreaOfCircle(r) {

return Math.PI * (r * r);

}

2
New cards

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];

}

3
New cards

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;

}

4
New cards

Function BDYearCalculator to accept age and return the birthday year.

function BDYearCalculator(age) {

var today = new Date( );

return (today.getFullYear( ) - age);

}

5
New cards

Function Greeting to accept name and return the greeting to the user

function Greeting(name) {

return var greeting = " Hi " + name + " Welcome to the website.";

}

6
New cards

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) );

}

7
New cards

Function FourDigitRandomGenerator to return a 4-digit random integer.

function FourDigitRandomGenerator( ) {

return Math.floor(1000 + Math.random( )*8999);

}

8
New cards

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;

9
New cards

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;

10
New cards

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

11
New cards

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

12
New cards

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("
");

}

}

13
New cards

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)];

}

14
New cards

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];

}

15
New cards

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( )]);

16
New cards

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 + "
");