Question

A.   Consider the following JavaScript code segment: message = ''; if (num1 > num2) { message...

A.   Consider the following JavaScript code segment:

message = '';
if (num1 > num2) {
message = message + 'ONE-';
num1 = num1 - num2;
}
else {
message = message + 'TWO-';
if (num1 * num2 <= 100) {
message = message + 'THREE-';
num1 = num1 / 2;
}
}
message = message + num1;

•   Assuming num1 = 8 and num2 = 8, what is the value of message after executing the above code?

•   Assuming num1 = 12 and num2 = 9, what is the value of message after executing the above code?

•   Assuming num1 = 9 and num2 = 12, what is the value of message after executing the above code?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi,

The answers for your question is as follows. I have included the code and the output.

If you need more information or have any questions, drop me a message.

If this answer helps you, please upvote it. Thank you.

The value of messages for each of the executions are in the following order.

1. TWO-THREE-

2. ONE-

3. TWO-

The JS code to test these inputs is


<html>
<head>
<script>
function calc() {
printValues(8, 8);
printValues(12, 9);
printValues(9, 12);
}
function printValues(num1, num2) {
message = '';
if (num1 > num2) {
message = message + 'ONE-';
num1 = num1 - num2;
}
else {
message = message + 'TWO-';
if (num1 * num2 <= 100) {
message = message + 'THREE-';
num1 = num1 / 2;
}
}
console.log(message);
}
</script>
</head>
<body onload="calc()">
</body>
</html>

Add a comment
Know the answer?
Add Answer to:
A.   Consider the following JavaScript code segment: message = ''; if (num1 > num2) { message...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is an external javascript file // Problem 1:   Declare the variables num1, num2, ans1, //  ...

    This is an external javascript file // Problem 1:   Declare the variables num1, num2, ans1, //               greet1, greet2. Then initialize them to //               hold the values 1, 2, 0, "Hello", and //               "World", respectively. var num1 = 1; var num2 = 2; var ans1 = 0; var greet1 = "Hello"; var greet2 = "World"; // Problem 1a:   Display the values stored in the previous //               variables in the...

  • Read the following code and determine what is the decimal values of num1 and num2 after...

    Read the following code and determine what is the decimal values of num1 and num2 after execution of the code. short num1 = 25, num2 = 0x7A, temp ; short *x; temp = num2; // num1 = ? num2 = ? x = &num1; // num1 = ? num2 = ? num2 = num1; // num1 = ? num2 = ? *x = temp; // num1 = ? num2 = ?

  • Given the following code… var num1 = 31; var num2 = 96; var num3 = 22;...

    Given the following code… var num1 = 31; var num2 = 96; var num3 = 22; var temp = num2; num3 = temp + num1; num1 = num1 + num3 var num4 = num3 + 11; num2 = num2 + num4; var ans = num1 + num2 + num3; What is the final value that is assigned to ‘ans’?

  • Consider the mathematical expression (num1 + num2) × (num3 − num4). We have been asked to...

    Consider the mathematical expression (num1 + num2) × (num3 − num4). We have been asked to replace num1, num2, num3 and num4 by numbers between 1 and 35, i.e. numbers from the set {1, . . . , 35}, so that after substituting these numbers in place of num1, num2, num3 and num4, the evaluation of the expression using PEDMAS leads to an odd positive integer. Find the number of ways in which this can be done. For example, one...

  • 1. Consider the following code segment. String str = "AP"; str += "CS " + 1...

    1. Consider the following code segment. String str = "AP"; str += "CS " + 1 + 2; System.out.println(str); What is printed as a result of executing the code segment? A: CS AP12 B: AP CS3 C: CSAP 12 D: APCS 12 E: APCS 3 2. Consider the following code segment. String dessert = "pie"; dessert += "straw" + dessert + "berry"; What is the value of dessert after the code segment has been executed? A: strawpieberry B: piestrawpieberry C:...

  • Consider the code fragment (assumed to be in a program in which all variables are correctly...

    Consider the code fragment (assumed to be in a program in which all variables are correctly defined): int num1, num2; double answer; // program gets num1 and num2 from user, and values received // are always non-zero ints between -100 and +100 (code not shown) ... // compute precise quotient: answer = static_cast<double>( num1 / num2 ); After the assignment statement the variable answer, will hold the most precise quotient possible, accurate to several digits to the right of the...

  • Assume the following code is executed on the PIPE machine that does forwarding: Охо00: pos irmovq num1,%rsi 0x000: 30f6...

    Assume the following code is executed on the PIPE machine that does forwarding: Охо00: pos irmovq num1,%rsi 0x000: 30f65800000000000000 | irmovq num2, *rdi mrmovq (%rsi), %rsi mrmovq (rdi), %rdi subq rdi, rsi j less 0x00a: 30f76000000000000000 0x014: 50660000000000000000 I 0x01e: 50770000000000000000 0x028: 6176 rsi rdi 0x02a: 724600000000000000 0x033: 30f00000000000000000 I irmovq s0, rax jmp done irmovq $1,rax 0x03d: 705000000000000000 0x046: 30f00100000000000000 | less: done: 0x050: 00 halt 0x058 .align 8 0x058: 0c00000000000000 num1: .quad 12 0x060: 0800000000000000 num2 8 penb...

  • What is the value of GPA when grade is 'B' in the following code segment? int...

    What is the value of GPA when grade is 'B' in the following code segment? int GPA=0; switch (grade) { case 'A': case 'a': GPA = GPA + 1; case 'B': case 'b': GPA = GPA + 1; case 'C': case 'c': GPA = GPA + 1; case 'D': case 'd': GPA = GPA + 1; } 4 3 2 1 None of the above #2.   Branching - switch statements... Extra info/hint? It's free What is the value of GPA when...

  • Given the following: struct Val { int num1; float num2; } ; struct Person { int...

    Given the following: struct Val { int num1; float num2; } ; struct Person { int age; float income; }; Val t, s; Person p1, p2, p3;                                        s.num1 = 0; s.num2 = 2.5;                          //initialize s p2.age = 25; p2.income = 9999.99;                //initialize p2 t = s;                            //assignment one p1 = s;                       //assignment two p2 = p3;                      //assignment three p3.age = s.num1;     //assignment four p3.income = s.num1;   //assignment five p2.age = t.num2;      //assignment six For each assignment statements above...

  • Python: 1) Consider the following code segment: try : inputFile = open("lyrics.txt", "r") line = inputFile.readline()...

    Python: 1) Consider the following code segment: try : inputFile = open("lyrics.txt", "r") line = inputFile.readline() print(line) _____________________ print("Error") What should be placed in the blank so that the program will print Error instead of crashing if an exception occurs while opening or reading from the file? Group of answer choices a- except RuntimeError : b- except EnvironmentError : c- except IOError : d- except IndexError : 2) Consider the following code segment: line = "hello world!" parts = line.split()...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT