JAVASCRIPT PRACTICE EXAM 2
TESTING QUESTIONS AND ANSWERS
You have a line of code in a webpage and want to make sure it displays only
if the browser a user is using does not support JavaScript.
Using drag and drop, drag the correct set of tags into the missing areas. Not
all tags will be used. - ANSWER-<noscript>
This browser does not support JavaScript.
</noscript>
For each statement regarding the use of external scripts, select Yes if the
statement is true or No if the statement is false. - ANSWER-External scripts
increase overall code security for websites. YES
If a variable is declared in both an inline script and an external script, the
inline script always takes precedence. NO
External scripts do not not need script tags within them. YES
A new developer is using the Console window within a browser to test code
for a new web app. The developer wants to be able to pause the code from
running to test the validity of variables within the code. Which methods can
the developer use to pause code as necessary? (Choose two) - ANSWER-add
a breakpoint
add the code word, debugger
Evaluate the following code:
rate = 5.99 document.getElementById("results").innerHTML =
parseInt("22 23") +
, parseFloat(" 25.99 is the price") +
parseInt(" The cat is 10") +
rate.toFixed(1);
What is the output of the code? - ANSWER-22 25.99 NaN 6.0
On a webpage that is used as a reporting page for your site, you are
attempting to display how many times the productList class is being used,
with the number of times the class is used to be displayed in a paragraph
with an ID of productListOutput.
Using the dropdown arrows, complete the function with the correct lines of
code. - ANSWER-var classList = document.getElementsByClassName
document.getElementById('productListOutput').innerHTML
You are writing code to generate a random number of 0, 1, or 2 so that a
song can be played based on the number generated.
Using drag and drop, fill in the variable declaration for the songNumber
variable. - ANSWER-Math.floor
Math.random
3
In the following code example, use the dropdown lists to complete the code
so that it will do the following:
Attempt to display an order total.
Display the message "You have a problem" and the error message if there is
an error.
TESTING QUESTIONS AND ANSWERS
You have a line of code in a webpage and want to make sure it displays only
if the browser a user is using does not support JavaScript.
Using drag and drop, drag the correct set of tags into the missing areas. Not
all tags will be used. - ANSWER-<noscript>
This browser does not support JavaScript.
</noscript>
For each statement regarding the use of external scripts, select Yes if the
statement is true or No if the statement is false. - ANSWER-External scripts
increase overall code security for websites. YES
If a variable is declared in both an inline script and an external script, the
inline script always takes precedence. NO
External scripts do not not need script tags within them. YES
A new developer is using the Console window within a browser to test code
for a new web app. The developer wants to be able to pause the code from
running to test the validity of variables within the code. Which methods can
the developer use to pause code as necessary? (Choose two) - ANSWER-add
a breakpoint
add the code word, debugger
Evaluate the following code:
rate = 5.99 document.getElementById("results").innerHTML =
parseInt("22 23") +
, parseFloat(" 25.99 is the price") +
parseInt(" The cat is 10") +
rate.toFixed(1);
What is the output of the code? - ANSWER-22 25.99 NaN 6.0
On a webpage that is used as a reporting page for your site, you are
attempting to display how many times the productList class is being used,
with the number of times the class is used to be displayed in a paragraph
with an ID of productListOutput.
Using the dropdown arrows, complete the function with the correct lines of
code. - ANSWER-var classList = document.getElementsByClassName
document.getElementById('productListOutput').innerHTML
You are writing code to generate a random number of 0, 1, or 2 so that a
song can be played based on the number generated.
Using drag and drop, fill in the variable declaration for the songNumber
variable. - ANSWER-Math.floor
Math.random
3
In the following code example, use the dropdown lists to complete the code
so that it will do the following:
Attempt to display an order total.
Display the message "You have a problem" and the error message if there is
an error.