Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. You are asked to write a program that will display a letter that corresponds with a numeric rating system. The program should use a

1. You are asked to write a program that will display a letter that corresponds with a numeric rating system. The program should use a switch statement. The numeric rating is stored in a variable named rate and rate may equal 1, 2, 3, or 4. The corresponding letter is stored in a variable named grade and grade may be A, B, C, or D. Which is the test expression for this switch statement?

a.

rate

b.

grade

c.

1, 2, 3, or 4

d.

A, B, C, or D

2. What will display after the following code is run if z = 3?

switch(x)

{

case 1:

document.write("one!");

case 2:

document.write("two!");

case 3:

document.write("three!");

default:

document.write("go!");

a.

nothing will display

b.

three!

c.

one!two!three!

d.

one!two!three!go!

3. What will display after the following code is run if name = "Morris"?

if(name > "Joe")

document.write("Morris is a cat.");

else

document.write("Joe rules!");

a.

Joe rules!

b.

Morris is a cat.

c.

Morris is a cat.Joe rules!

d.

nothing cannot compare these values

4. Which statement is equivalent to the following:

(x >= 0) && (x <= 100)

a.

!(x < 0) && (x > 100)

b.

(x < 0) && (x > 100)

c.

(x >= 0) || (x <= 100)

d.

!((x < 0) || (x > 100))

5. What is the result of the following statement, given that count = 6?

if (count == 6)

a.

true

b.

false

c.

6

d.

not enough information given

6. Which statement is equivalent to the following?

(X > 6)

a.

!(x <= 6)

b.

( x <= 6)

c.

(x < 6 || x == 6

d.

(x < 6 && !(x == 6)

7. Which of the following will set the variable num to the value 8?

a.

num = pow(2, 3);

b.

num = sqrt(64);

c.

num = Math.pow(64, 2);

d.

num = Math.sqrt(64);

8. Which of the following will set the variable num to the value of 10 if num = 10.3625?

a.

num = floor(10.3625);

b.

num = Math.abs(10.3625);

c.

num = Math.floor(num);

d.

Math.floor(num);

9. Which of the following will generate a random number between 0 and 5?

a.

Math.random() * 5;

b.

Math.floor(Math.random() * 6));

c.

Math.random() * 5 + 1;

d.

Math.floor(Math.random() * 4 + 1);

10. Which of the following will generate a random number between 1 and 6?

a.

Math.random() * 6;

b.

Math.floor(Math.random() * 5 + 1));

c.

Math.random() * 6 + 1;

d.

Math.floor(Math.random() * 6 + 1);

TRUE/FALSE

1. True/False: In an if... structure, the only possible outcomes are either: a block of statements are executed or nothing is executed.

2. True/False: A valid test condition could be (x = 10), assuming x is an integer variable.

3. True/False: The following test condition for an if... structure will be true if x = 2:

if(x < 5 && x > 10)

4. True/False: The result of any test condition is always either true or false.

5. True/False: The following test condition will evaluate to true if x = 5:

if(x < 3 || x == 5)

6. True/False: The following statements are equivalent, given that x = 4 and y = 3:

z = Math.pow(y, x);

and z = x * x * x;

7. True/False: While it is possible to nest an if...else structure within an if... structure, it is not possible to nest an if... structure inside if...else structure.

8. True/False: The if clause and the else clause of an if...else structure must always contain different test conditions.

9. True/False: If an if clause or an else clause contain only one statement, curly brackets are not necessary.

10. True/False: A switch structure is a multiple alternative selection structure.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions