100% found this document useful (1 vote)
92 views16 pages

Quiz and Test Module 3-SOLVED

Test y preguntas sobre el módulo 3 de Python

Uploaded by

josegmay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
92 views16 pages

Quiz and Test Module 3-SOLVED

Test y preguntas sobre el módulo 3 de Python

Uploaded by

josegmay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Quiz and Test (JSE) Module 3 - SOLVED

Centro público integrado de formación profesional


Nuevo (desglose IES Campanillas)

Quiz and Test


JavaScript Essentials 1 (JSE)
Module 3
SOLVED

José García JavaScript - JSE-40-01


Quiz and Test (JSE) Module 3 - SOLVED

Índice
JAVASCRIPT ESSENTIALS 1 (JSE) - MODULE 3 .............................................................................................................................3
JAVASCRIPT ESSENTIALS 1 (JSE) MODULE 3 ........................................................................................................................................................... 3
Operators and User Interaction ............................................................................................................................................................................. 3
QUIZ ....................................................................................................................................................................................................................4
TEST ................................................................................................................................................................................................................ 10

José García 2 JavaScript - JSE-40-01


Quiz and Test (JSE) Module 3 - SOLVED
JavaScript Essentials 1 (JSE) - Module 3 - SOLVED

JavaScript Essentials 1 (JSE)


Module 3

Operators and User Interaction


After completing Module 3, the student will:

• know what operators are and how to classify them (by type of operand, by number of operands, etc.);
• be able to use assignment, arithmetic, logical, and comparison operators in practice;
• understand the operation of the conditional operator and the typeof, instanceof, and delete operators;
• understand what the precedence and associativity of basic operators are and be able to influence them
by means of bracket grouping;
• be able to perform basic two-way communication with the program user using the alert, confirm, and
prompt dialog boxes.

José García 3 JavaScript - JSE-40-01


Quiz and Test (JSE) Module 3 - SOLVED
Quiz
Analyze the code snippet:
let n = 5 + 2 ** 2 * 3:
The result stored in the variable n is:
a. 117649
b. 42
c. 84
d. 17

To analyze the code snippet, let's break it down step by step:

1.- The snippet starts with let n = which means we are declaring a variable n.
2.- Next, we have 5 + 2 ** 2 * 3.

Now, let's evaluate the expression step by step:


a.- First, the exponentiation operation is performed: 2 ** 2 which equals 4.
b.- Next, we have the multiplication operation: 4 * 3 which equals 12.
c.- Finally, we have the addition operation: 5 + 12 which equals 17.
So, the result stored in the variable n is 17.

The correct answer is:

d.- 17

The number 3 is stored in the variable x: (let x =3;). The command x=x*x wasthen called. This last
command can be replaced using:
a. x**=2;
b. x**=x;
c. x+=x;
d. x*= 2;

To replace the last command x = x * x using a shorthand assignment operator, you need to find
the correct shorthand operator that achieves the same result.
Given that x = 3, the command x = x * x will square the value of x.

Let's see the shorthand assignment options and their effects:


a.- x **= 2; - This will perform the exponentiation operation and square the value of x, which is
equivalent to x = x ** 2.
b.- x **= x; - This will perform the exponentiation operation with x as the exponent, which is
equivalent to x = x ** x, not squaring.
c.- x += x; - This will perform addition and effectively double the value of x, which is equivalent to
x = x + x, not squaring.
d.- x *= 2; - This will perform multiplication and double the value of x, which is equivalent to x =
x * 2, not squaring.
To achieve the same result as x = x * x (which is squaring x), the correct shorthand assignment
is:
a.- x **= 2;

So the correct answer is:

a.- x **= 2;

José García 4 JavaScript - JSE-40-01


Quiz and Test (JSE) Module 3 - SOLVED
The string "1024" has been written into the str variable: (let str - "1024";).
Then the operation str = -str is performed. As a result, the variable str will contain:
a. -1024
b. "1024"
c. "-1024"
d. NaN

In JavaScript, when you use the unary negation operator - on a string that represents a number, it tries
to convert the string to a number and then negates it. If the conversion is successful, it negates the
numeric value. If the string cannot be converted to a number, it results in NaN (Not-a-Number).

Let's analyze the code:


1.- let str = "1024"; - This initializes the variable str with the string value "1024".
2.- str = -str; - This applies the unary negation operator to the variable str.

Now, let's evaluate the operation step by step:


a.- Convert "1024" to a number: The string "1024" can be successfully converted to the number
1024.
b.- Negate the number: -1024
So, the variable str will contain the value -1024.

The correct answer is:

a.- -1024

Analyze the code snippet:


let n = 10;
let m = n++;
Its execution will result in the following values in the variables n and m
a. n. 10, m. 11
b. n: 11, m: 11
c. n: 11, m: 10
d. n: 10, m: 10

Let's analyze the code snippet step by step:


let n = 10; - This initializes the variable n with the value 10.
let m = n++; - This initializes the variable m with the value of n before the increment (post-increment).
The post-increment operator ++ increments the value of n by 1 after the assignment is performed.

Now, let's see the result:


a.- n: 10, m: 11 - This is incorrect. The value of n remains 10 because the increment happens after
the assignment to m.
b.- n: 11, m: 11 - This is also incorrect. The value of n is incremented to 11 after the assignment to
m.
c.- n: 11, m: 10 - This is correct. The value of n is incremented to 11 after the assignment to m, and
m receives the original value of n, which was 10.
d.- n: 10, m: 10 - This is incorrect. The value of n is incremented to 11 after the assignment to m.

So, the correct answer is:

c.- n: 11, m: 10

José García 5 JavaScript - JSE-40-01


Quiz and Test (JSE) Module 3 - SOLVED
The result of the operation true && false I| true will bet
a. null
b. true
c. false
d. 1

Let's break down the expression step by step:


1.- true && false - The logical AND operator && returns false if any of its operands are false.
In this case, since the first operand is true and the second operand is false, the result of this
expression is false.
2.- true | true - The single pipe | is the bitwise OR operator, not the logical OR operator. The
logical OR operator in JavaScript is represented by ||. The bitwise OR operator performs a bitwise
OR operation on the operands. In this case, true is implicitly converted to the number 1, so the
operation true | true is equivalent to 1 | 1, which results in 1.

Now, let's combine the results:


The expression becomes: false | 1
The bitwise OR operation is performed between false (which is implicitly converted to 0) and 1,
resulting in 1.

So, the correct answer is:

d.- 1

The result of the operation 20 && 5 will be:


a. 25
b. true
c. 5
d. 20

The expression 20 && 5 uses the logical AND operator &&. In JavaScript, the logical AND
operator returns the value of the second operand if both operands are truthy. If the first operand
is falsy, it immediately returns that value without evaluating the second operand.

Truthy values in JavaScript include non-zero numbers (like 20 and 5) and non-empty strings,
among others. Falsy values include 0, null, undefined, false, and empty strings ("").

Now, let's evaluate the expression:


1.- 20 is a truthy value.
1.- 5 is also a truthy value.
Since both operands are truthy, the logical AND operator returns the value of the second
operand, which is 5.

So, the correct answer is:

c.- 5

José García 6 JavaScript - JSE-40-01


Quiz and Test (JSE) Module 3 - SOLVED
The result of the operation true && "false" will be:
a. true
b. false
c. 0
d. "false"

In the expression true && "false", the logical AND operator && is used.

The logical AND operator in JavaScript works as follows:


• If the first operand is truthy, it evaluates and returns the second operand.
• If the first operand is falsy, it immediately returns that value without evaluating the second
operand.

Truthy values include true, non-empty strings, and non-zero numbers, among others. Falsy values
include false, null, undefined, 0, and empty strings ("").
Now, let's evaluate the expression:
1.- true is a truthy value.
2.- "false" is a non-empty string, so it is also a truthy value.
Since both operands are truthy, the logical AND operator returns the value of the second operand,
which is "false".

So, the correct answer is:

d.- "false"

Analyze the code snippet:


let str = "10";
let a = (str = 10);
let b = (str == 10);
let c = (str === 10);
After its execution the variables a, b and a will have the values:
a. a: 10. b: false, c: true
b. a: 10, b: 10, c: 10
c. a: 10, b: true, c: false
d. a: 10. b: null, c: null

Let's analyze the code snippet step by step:


1.- let str = "10"; - This initializes the variable str with the string value "10".
2.- let a = (str = 10); - This assigns the value 10 to the variable str, and the assignment expression
(str = 10) also returns the assigned value 10. So, the value of a becomes 10.
3.- let b = (str == 10); - This uses the loose equality operator == to check if the value of str is equal
to 10. Since str now holds the number 10, the loose equality comparison with 10 returns true. So, the
value of b becomes true.
4.- let c = (str === 10); - This uses the strict equality operator === to check if the value of str is
equal to 10. However, str is currently a number 10, and not a string, so the strict equality comparison
with the number 10 returns true. So, the value of c becomes true.

Now, let's summarize the correct values of the variables:


a.- a: 10, b: true, c: true

So, the correct answer is:

a.- a: 10, b: true, c: true

José García 7 JavaScript - JSE-40-01


Quiz and Test (JSE) Module 3 - SOLVED
Which operator do we use if we want to check if two variables store different values?
a. !==
b. <>
c. Diff
d. =!

The operator we use to check if two variables store different values is:

a.- !== (strict not equal)

The !== operator is the strict inequality operator in JavaScript, which checks if two values are not
equal, both in value and in type. It returns true if the values are different, and false if they are
equal.

The result of the comparison "abcd" > "dc" will be:


a. “abcd”
b. -1
c. false
d. true

To compare two strings in JavaScript, the comparison is performed character by character based
on their Unicode code points. The comparison stops when the first differing characters are found.

Let's compare the strings "abcd" and "dc" character by character:


1.- The first characters are compared: 'a' (97 in Unicode) and 'd' (100 in Unicode). Since 'a' (97)
comes before 'd' (100) in Unicode, "abcd" is considered to be less than "dc".
As soon as a character comparison determines the result, the comparison stops, and the overall
result is determined.

So, the correct answer is:

c.- false

The result of the operation 6 * 2 < 20 - 15 will be:


a. -9
b. NaN
c. false
d. true

Let's evaluate the expression step by step:


1.- 6 * 2 - This evaluates to 12.
2.- 20 - 15 - This evaluates to 5.
3.- Now we have 12 < 5.

The less-than operator < checks if the value on the left is less than the value on the right. In this
case, 12 is not less than 5, so the expression 12 < 5 evaluates to false.

So, the correct answer is:

c.- false

José García 8 JavaScript - JSE-40-01


Quiz and Test (JSE) Module 3 - SOLVED
Which method will display a dialog box that allows the user to type in any string?
a. alert
b. confirm
c. prompt
d. fill

The method that will display a dialog box that allows the user to type in any string is:

c.- prompt

The prompt() method displays a dialog box with an optional message and an input field where
the user can type in a string. The user can then enter a string and click OK or Cancel. If the user
clicks OK, the entered string is returned as the result of the prompt() method. If the user clicks
Cancel or closes the dialog, the method returns null.

The confirm method allows you to create a dialog box. What value does this method return when the
user closes the window?
a. It depends on the option selected by the user.
b. It always returns false .
c. The string entered by the user.
d. It always returns true.

The correct answer is:

a.- It depends on the option selected by the user.

The confirm() method displays a dialog box with a message and two buttons: "OK" and
"Cancel". When the user interacts with the dialog box, the method returns a boolean value based
on the user's choice:
• If the user clicks "OK", the method returns true.
• If the user clicks "Cancel" or closes the dialog, the method returns false.

Analyze the following code:


let choice = confirm("Are you ready?") ? "true":"false"
What value will the choice variable have if we press the OK button in the dialog box after running the
code?
a. true
b. "ОК"
c. false
d. "true"

The code you provided uses the confirm() method to display a dialog box with the message "Are
you ready?" and two buttons: "OK" and "Cancel".
If the user presses the "OK" button in the dialog box, the confirm() method returns true.
Otherwise, if the user clicks "Cancel" or closes the dialog, the method returns false.
After running the code and pressing the "OK" button in the dialog box, the value of the choice
variable will be:

a.- true

The ternary operator ? : is used to assign the value based on the result of the confirm() method.
If the confirm() method returns true, the value of choice will be "true". Since the confirm()
method returns true when the "OK" button is pressed, the value of choice will be true.

José García 9 JavaScript - JSE-40-01


Quiz and Test (JSE) Module 3 - SOLVED
Test
The number 2 is stored in the variable n (let n – 2;). The command n = n*n*n is then called. This
last command can be replaced by:
a. n***=n;
b. n**=3;
c. n**=n;
d. n*=3;

To replace the last command n = n * n * n using a shorthand assignment operator, you need to
find the correct shorthand operator that achieves the same result.
Given that n = 2, the last command n = n * n * n will perform the operation 2 * 2 * 2, which
equals 8.

Now, let's evaluate the shorthand assignment options:


a.- n ***= n; - This is not a valid shorthand assignment operator in JavaScript.
b.- n **= 3; - This will perform the exponentiation operation and raise n to the power of 3, which
is equivalent to n = n ** 3. Since n is 2, n **= 3 will result in n = 8, which is the desired result.
c.- n **= n; - This will also perform the exponentiation operation, but it will raise n to the power of
itself, which is equivalent to n = n ** n. Since n is 2, n **= n will result in n = 4, not the desired
result.
d.- n *= 3; - This will perform multiplication and multiply n by 3, which is equivalent to n = n * 3.
Since n is 2, n *= 3 will result in n = 6, not the desired result.

So, the correct answer is:

b.- n **= 3;

José García 10 JavaScript - JSE-40-01


Quiz and Test (JSE) Module 3 - SOLVED
Analyze the code snippet:
let nr = "1";
let x = (nr === 1);
let y = (nr == 1);
let z = (nr = 1);
After its execution, the variables ×, y, and z will have the values:
a. x: 1,y: 1, z: 1
b. x: true, y: false, z: 1
c. x: false, y: true, z: 1
d. x: null, y: null, z: 1

Let's analyze the code snippet step by step:


1.- let nr = "1"; - This initializes the variable nr with the string value "1".
2.- let x = (nr === 1); - This uses the strict equality operator === to check if the value of nr is
equal to 1, but since nr is a string and not a number, the strict equality comparison with the
number 1 returns false. So, the value of x becomes false.
3.- let y = (nr == 1); - This uses the loose equality operator == to check if the value of nr is
equal to 1. The loose equality comparison tries to perform type coercion to compare values of
different types. In this case, since nr is a string and 1 is a number, the loose equality comparison
returns true if the string can be successfully converted to a number with the same value. In this
case, "1" can be converted to the number 1, so the value of y becomes true.
4.- let z = (nr = 1); - This is an assignment expression. It assigns the value 1 to the variable nr
and also returns the assigned value 1. So, the value of z becomes 1.

Now, let's summarize the correct values of the variables:


a.- x: false, y: true, z: 1

So, the correct answer is:

c.- x: false, y: true, z: 1

Analyze the following code:


let test = prompt ("Hello", "World");
What value will the test variable have if, after running the code, we immediately press the OK button on
the newly created dialog?
a. "ОК"
b. true
c. "World"
d. "Hello"

If, after running the code, we immediately press the OK button on the newly created dialog, the
value of the test variable will be:

c.- "World"

The prompt() method displays a dialog box with two buttons: "OK" and "Cancel", along with a
text input field where the user can enter a value. The text input field will contain the default value
"World" as specified in the second argument of the prompt() method.
If the user presses the OK button without entering any value or just clicks OK without making any
changes, the prompt() method will return the default value, which is "World" in this case.
Therefore, the ‘test’ variable will have the value "World".

José García 11 JavaScript - JSE-40-01


Quiz and Test (JSE) Module 3 - SOLVED
The confirm method allows you to create a dialog box. What value does this method return when the
user closes the window?
a. The string entered by the user.
b. It depends on the option selected by the user.
c. Always false.
d. Always true

When the user closes the window of the confirm dialog box (by clicking the "Cancel" button or
closing the dialog), the confirm() method returns:

c.- Always false.

The confirm() method returns a boolean value based on the user's choice. If the user clicks the
"OK" button in the dialog, the method returns true. But if the user clicks the "Cancel" button or
closes the dialog, the method returns false.

The result of the operation 20 | | 5 will be:


a. true
b. 25
c. 5
d. 20

The expression 20 || 5 uses the logical OR operator ||.

The logical OR operator in JavaScript works as follows:


• If the first operand is truthy, it immediately returns that value without evaluating the second
operand.
• If the first operand is falsy, it evaluates the second operand and returns it.
In this case, 20 is a truthy value. Since the logical OR operator returns the first truthy value
encountered, the expression 20 || 5 will immediately return 20.

So, the correct answer is:

d.- 20

The result of the operation 3 * 4 > 20 - 15 will be:


a. -14
b. NaN
c. true
d. false

Let's evaluate the expression step by step:


1.- 3 * 4 - This evaluates to 12.
2.- 20 - 15 - This evaluates to 5.
3.- Now we have 12 > 5.

The greater-than operator > checks if the value on the left is greater than the value on the right.
In this case, 12 is greater than 5, so the expression 12 > 5 evaluates to true.

So, the correct answer is:

c.- true

José García 12 JavaScript - JSE-40-01


Quiz and Test (JSE) Module 3 - SOLVED
Analyze the code snippet:
let n = 2 * 3 ** 3 - 1;
The result stored in the variable n is:
a. 36
b. 18
c. 215
d. 53

To analyze the code snippet, let's break it down step by step:


1.- 2 * 3 ** 3 - The expression 3 ** 3 represents the exponentiation operation, which is 3 raised
to the power of 3, resulting in 27. Then, 2 * 27 equals 54.
2.- 54 - 1 - Subtracting 1 from 54, we get 53.

So, the result stored in the variable n is 53.

The correct answer is:

d.- 53

The result of the operation ! (true 66 false || true) will be:


a. 1
b. null
c. false
d. true

To evaluate the expression, let's break it down step by step:


1.- true || false - The logical OR operator || evaluates to true if any of its operands are true. In
this case, true || false evaluates to true.
2.- true || true - The second operand is true, so the expression true || true still evaluates to
true.
3.- !(true || true) - The logical NOT operator ! negates the result. Since the result of true || true
is true, the negation gives us false.

So, the correct answer is:

c.- false

José García 13 JavaScript - JSE-40-01


Quiz and Test (JSE) Module 3 - SOLVED
The string "12" has been written into the str variable: ( let str = "12"; ). Then the operation str = +str
is performed. As a result, the variable str will contain:
a. NaN
b. “+12”
c. “12”
d. 12

Let's analyze the code snippet step by step:


1.- let str = "12"; - This initializes the variable str with the string value "12".
2.- str = +str; - The unary plus + is used here to perform type conversion. When applied to a string, it attempts
to convert the string to a numeric value.

Now, let's evaluate the operation:


The string "12" can be successfully converted to the number 12 using the unary plus +. So, after the operation
str = +str, the variable str will contain the numeric value 12.

So, the correct answer is:

d.- 12

Analyze the code snippet:


let n = 10;
let m = ++n;
Its execution will result in the following values in the variables n and m:
a. n: 11, m: 11
b. n: 10, m: 11
c. n: 11, m: 10
d. n: 10 , m: 10

Let's analyze the code snippet step by step:


1.- let n = 10; - This initializes the variable n with the value 10.
2.- let m = ++n; - This uses the pre-increment operator ++ on n. The pre-increment operator
increments the value of n by 1 before the assignment is performed. So, n becomes 11, and the
value of m is equal to the updated value of n, which is 11.

After executing the code snippet, the values of the variables n and m will be:
a. n: 11, m: 11

So, the correct answer is:

a.- n: 11, m: 11

José García 14 JavaScript - JSE-40-01


Quiz and Test (JSE) Module 3 - SOLVED
The result of the comparison "abcd" > "Abcd" will be:
a. “abcd”
b. 1
c. true
d. false

In JavaScript, when comparing strings using the greater-than operator (>), the comparison is
based on the Unicode code point value of each character in the strings. The comparison is done
character by character from left to right until the first differing characters are found.

Now, let's compare the strings "abcd" and "Abcd" character by character:
1.- The first characters are compared: 'a' (Unicode code point 97) and 'A' (Unicode code point
65). The Unicode code point of 'a' (97) is greater than the Unicode code point of 'A' (65), so
"abcd" is considered to be greater than "Abcd".

Since the comparison has determined the result, the evaluation stops, and the overall result is
determined.

So, the correct answer is:

c.- true

Which operator do we use if we want to check if two variables store the same values of exactly the same
type?
a. ===
b. =
c. !==
d. ==

The operator we use to check if two variables store the same values of exactly the same type is:

a.- === (strict equality)

The === operator is the strict equality operator in JavaScript, which checks if two values are
equal, both in value and in type. It returns true if the values are the same and of the same type,
and false if they are not.

José García 15 JavaScript - JSE-40-01


Quiz and Test (JSE) Module 3 - SOLVED
The methods window.alert, window.confirm, and window.prompt are methods of the window
object. Which of the following is not true?
a. The methods window.alert, window.confirm, and window.prompt are methods of the window object. Which
of the following is not true?
b. The window object represents the window in which the HTML document containing the JavaScript code
currently being executed is open.
c. The alert, confirm, and prompt methods display information in modal windows that block access to the
page until they are closed.
d. You can call window methods, such as window.alert, without including the name window, so calling alert
("abc") would be correct.

The statement that is not true is:

a.- The methods window.alert, window.confirm, and window.prompt are methods of the window object.

Explanation:
a.- This statement is true. The window.alert, window.confirm, and window.prompt methods
are indeed methods of the window object in JavaScript.
b.- This statement is true. The window object represents the window in which the HTML
document containing the JavaScript code currently being executed is open. It serves as the
global object in the browser environment.
c.- This statement is true. The alert, confirm, and prompt methods display modal windows that
block access to the page until they are closed by the user.
d.- This statement is not true. In the global scope of a browser environment, you can call window
methods, such as window.alert, without explicitly including the name "window". For example,
calling alert("abc") would be correct, and it would display the same alert as
window.alert("abc"). However, if you are working in a local scope (e.g., inside a function), you
need to include the window object explicitly to avoid referencing a local variable with the same
name.

The result of the operation false || "false" will be:


a. 0
b. “false”
c. false
d. true

The result of the operation false || "false" will be:

b. "false"

The logical OR operator || in JavaScript returns the first truthy value it encounters, or the last
value if all operands are falsy. In this case, the first operand is false, which is falsy. Since the
second operand is a non-empty string "false", which is a truthy value, the logical OR operator
returns "false".

José García 16 JavaScript - JSE-40-01

You might also like