• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/68

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

68 Cards in this Set

  • Front
  • Back
switch is a legal identifier in JavaScript.
False
count++; is equivalent to count = count + 1;
True
Every function must have a return statement.
False
In JavaScript, the function keyword is used to define a function.
True
When a function is called, its local variables initially contain the value 0.
False
Actual and formal function parameters must have the same name.
False
A function always returns the value 0.
False
When a function is called, the number of arguments passed should match the number of formal parameters.
True
After a function has returned, the values stored in its local variables are copied into variables in the calling function that have the same name.
False
The values stored in the local variables of a function are not saved when the function exits.
True
Formal parameters must also be declared inside of a function using the var keyword.
False
JavaScript is an interpreted language.
True
If the variables a and b are holding the values 0 and 1, respectively, what is the value of the following expression : ( a || b ) ?
True
If the variables a and b are holding the values 0 and 1, respectively, what is the value of the following expression : ( a && b ) ?
False
If the variables a and b are holding the values 1 and 2, respectively, what is the value of the following expression : ( a + b ) ?
True
If the variables a and b are holding the values 0 and 6, respectively, after the statement a += b the new values of a and b are both 6.
False
All array elements are initialized to 0 when the array is created.
False
The default case is required in the switch selection structure.
False
The default case must be the last case in the switch selection structure.
False
The break statement is required in the default case of the switch selection structure.
False
An array is used store a list of items.
True
Array subscripts must always start at 0.
True
The function keyword is used when making a function call.
False
The fourth element of an array named bob is bob[4]
False
Arrays must always be initialized using a for loop.
False
Given the function call,
PrintGreeting();
how many arguments does the function have?
0
The function header comment
[b.] gives information about the function to the person reading the code.
What is the output of the following code fragment?
var a = 3, b = 17 ;

a = b % a ;
b++ ;
alert("a = " + a + ", b = " + b);
[d.] a = 2, b = 18
The output of the following program fragment is:
test = 1 ;
if (test = 2) {
alert("Beam down the landing party.\n") ;
} else if (test == 1) {
alert("Jim, he's dead.\n") ;
} else if (test == 0) {
alert("Scotty, four to beam up.\n") ;
[a.] Beam down the landing party.
Which of the following statements will print out the variable x with exactly 1 decimal place, e.g. 123.4
[a.] alert (x.toFixed(1));
A single JavaScript statement that decrements the value of x, giving x a new value is
[a.] x--;
How many arguments does the following function call have?
ave = FindAverage(num1, num1);
2
How many arguments does the following function call have?
PrintMessage("Hello there!");
1
Which of the following is a function header for a function that has only 1 parameter?
[b.] function AddOne(num1)
What is the index of the last element in an array of size 10?
[c.] 9
The character used to display a newline in an alert statement is
[a.] \n
The tag used to display a newline in a document.write() statement is
[d.] <br />
Which operator can be used on strings and numbers?
[b.] +
How can you increment the variable num by 1?
[a.] num++
[b.] num = num + 1
[c.] num += 1
When a variable is declared, what is its initial value?
NULL (aka empty)
Explain why it is sometimes necessary to use parseInt() or parseFloat() after a call to prompt().
Because the prompt command doesn't know if it is capturing a string or a number
Briefly describe one reason to write your own functions.
It keeps you from having to write the same code over and over again
Write a function called SumTwo that returns the sum of two numbers, where the numbers, num1 and num2 are passed to it.
function SumTwo(num1, num2) {
return parseInt(num1) + parseInt(num2);
}
Name two benefits of using constants in a program.
You can't accidentally change the value of a constant. Constants make a program easier to modify
Write a function called Smallest that takes three arguments, x, y and z and returns the smallest of the three arguments. You can assume x, y and z are numbers.
function Smallest(x,y,z) {
var smallest = z;
if (y < smallest) {
smallest = y;
}
if (x < smallest) {
smallest = x;
}
return smallest;
What is the starting index of an array?
0
Briefly describe why the function definitions are placed in the <head> section of the document.
It is easier to organize and understand the program
Write a function called AlertEven that takes 1 argument, n, and alerts whether the value is even or not. The function should not return anything. For example if n is 6, the output would be "6 is even". If n is 7, the output would be "7 is not even".
function AlertEven(n) {
if (n % 2 == 0) {
alert("even");
} else {
alert("odd");
}
}
In an array declared with n elements, what is the index of the last element ?
n-1 because the first element of the array is index 0 (e.g. myarray[0] )
Write the statements that would declare a 10-element array and initialize all of its elements to 1.
var myarray = new Array(10);
myarray=1;
Write a function called Average that takes three number parameters n1, n2, and n3 and returns the value of the average of the three.
function Average(n1, n2, n3) {
return ((n1 + n2 + n3) / 3);
}
Write a function called SumN that takes one parameter, n, and returns the sum of the integers from 1 to n.
function SumN(n) {
var sum = 0;
var i;
for (i=1;i<=n;i++) {
sum = sum + i;
}
return sum;
}
Write a function called FeetToInches that takes numFeet as an argument and returns the number of inches in that many feet.
function FeetToInches(numFeet) {
return (numFeet * 12);
}
Write a function called PrintBox that will print a rectangle made up of any character passed to it. Here is the function header:
function PrintBox (rows, columns, ch)
This call to PrintBox,
PrintBox(3, 10, "$");

should print:
$$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$
function PrintBox(rows, columns, ch) {
var i;
var j;
for(i=1;i<=rows;i++) {
for(j=1;j<=rows;j++) {
document.write(ch);
}
}
}
Write a set of one or more statements that will print out one of the brief messages given in the table below, depending on a person's grade point average. Assume that the grade point average has already been read into a variable called gpa. Include code to print a warning message if the value of gpa is not in the range 0.0 to 4.0. You should decide which control structure (if, if-else, switch, etc...) is appropriate.
GPA range Student Rating
3.50 - 4.0 Dean's list
2.0 - 3.49 Satisfactory
1.0 - 1.99 Probation
0.0 - 0.99 Suspended
if (gpa < 0 || gpa > 4) {
alert("gpa is not correct");
} else {

document.write("<b>GPA range &nbsp;&nbsp;&nbsp; Student Rating");
if (gpa >= 3.50) {
document.write("3.50-4.0 &nbsp;&nbsp;&nbsp; Dean's List");
} else if (gpa >= 2.0) {
document.write("2.0-3.49 &nbsp;&nbsp;&nbsp; Satisfactory");
} else if (gpa >= 1.0) {
document.write("1.0 - 1.99 &nbsp;&nbsp;&nbsp; Probation");
} else {
document.write("0.0 - 0.99 &nbsp;&nbsp;&nbsp; Suspended");
}
}
Given an array of size 100 called numbers, write a code segment that would find the average of the array elements. You can assume that the array has already been initialized to hold values.
var sum = 0;
var i;
for (i=1;i<=99;i++){
sum=sum+numbers(i);
}
alert("Average is " + (sum / 100));
Given an array of size 100 called numbers, write a code segment that would find the smallest element in the array. You can assume that the array has already been initialized to hold values.
var smallest=numbers(0);
var i;
for(i=1;i<=99;i++){
if (numbers(i) < smallest) {
smallest = numbers(i);
}
}
alert("Smallest is " + smallest);
Given an array of size 100 called numbers, write a code segment that would find the largest element in the array. You can assume that the array has already been initialized to hold values.
var largest=numbers(0);
var i;
for(i=1;i<=99;i++){
if (numbers(i) > largest) {
largest = numbers(i);
}
}
alert("Largest is " + largest);
What is wrong with the following code segment? Modify the code so it works correctly.

var i = 1;

//this while loop displays the numbers 1-10
while (i <= 10)
{
alert("i is " + i);
i--;
}
var largest=numbers(0);
var i;
for(i=1;i<=99;i++){
if (numbers(i) > largest) {
largest = numbers(i);
}
}
alert("Largest is " + largest);
Give a description of a problem/program where you would use an array and explain why you would choose to use an array. What would the alternative to an array be?
Change the "i--" to "i++"
alert ("JavaScript\nis\nfun.");
Output:

JavaScript
is
fun.
var a = 2, b = 3;

b = b * a;
b++;
a += b;
alert (a + " " + b);
Output:

"9 7"
var a = 5, b = 4;

b += a;
b++;
a = a - b;
document.write (a + " " + b);
Output:

"5 10"
var n = 1234;

while (n > 0)
{
document.write(n + "<br />");
n = n / 10;
n = Math.floor(n);
}
/* Hint: The Math.floor() function truncates a number
downwards to the nearest integer. For example,
the floor of 34.5 would be 34 */
Output:

1234
123
12
1
var m;

for (m = 1; m <= 5; m++)
{
switch (m)
{
case 1:
document.write ("one");
break;
case 2:
document.write ("two");
break;
case 3:
document.write ("three");
break;
default:
document.write ("Default case");
}
document.write ("<br />");
}
Output:

one
two
three
Default case
Default case
var x;

for (x = 4; x >= 0; x--)
{
switch (x)
{
case 3:
document.write ("tres");
break;
case 2:
document.write ("dos");
break;
case 1:
document.write ("uno");
break;
default:
document.write ("Default case");
}
document.write ("<br />");
}
Output:

Default case
tres
dos
uno
Default case
<head>
<script type="text/javascript">
<!--
function X (m)
{
document.write("In function X: " + m + "<br />");
return (m + 2);
}
//-->
</script>
</head>
<body>
<script type="text/javascript">
<!--
var m;

m = X(5);
document.write("After the call to function X: " + m);
//-->
</script>
Output:

In function X:5
After the call to function X: 7
<head>
<script type="text/javascript">
<!--
function Foo (num)
{
num++;
document.write("In function Foo: " + num + "<br />");
return num;
}
//-->
</script>
</head>
<body>
<script type="text/javascript">
<!--
var num = 7;

Foo(num);
document.write("After the call to function Foo: " + num);
//-->
</script>
Output:

In function Foo:8
After the call to function Foo:8