JAVASCRIPT PRACTICE EXAM 1:
TESTING MODE
You have entered the following code into a webpage: <script> function incQty (field)
{ var qty document.getElementById(field).value; qty ++
document.getElementById(field).value qty; } function decQty (field) { qty
document.getElementById(field).value } qt - Correct Answers -Move the qty variable
above the incQty function
Declare the qty variable in the decQty function
You are building a website for a fitness company. You need to display a list of program
dates based on a start date and an end date. You need to build a loop that adds each
date to a bulleted list inside of an element called programList. The start and end dates
are seven days apart, and you need to show all dates in between the start and end
dates. The start date should always display. Using drag and drop, drag over the correct
code snippets in the proper order to build a loop of dates. Any needed variables have
already been declared. Not all options will be used. - Correct Answers -line 1
do {
line 2
document.getElement Byld("programList").in nerHTML += "<li>" + programDate + "
</li>";
line 3
programDate.setDate( programDate.getDate(( ) + 2);
line 4
}
line 5
while (programDate < programEndDate)
You are trying to fill a variable called activity with an activity based on the weather. The
activity to do will be based on the following scenarios: If it is at least 70 degrees and the
weather is clear, the activity will be golf. If it is less than 50 degrees or the weather is
not clear, the activity will be bowling. Otherwise, the activity is hiking. Drag the correct
operators into the missing code slots to finish building this code example. Not every
operator will be used. - Correct Answers -1)>=
, 2)&&
3)==
4)<
5)||
6)!=
You want to store a list of locations in an array, sorted in alphabetical order. You also
want an empty array for new locations, with the intention that the array is filled in with
new locations as needed. Using the dropdown lists, fill in the proper code to declare
both a filled array to the variable, locations, and an empty array to the variable
newLocations. Then, add the code for alphabetizing the locations array before it is
displayed and fill in the code that will make HQ the first element in the array. Finally,
add the code necessary to assign the number of elements in the array to the variable
numberOfLocations. Use the comments to help guide you as to where to add code for
each task. - Correct Answers -[
[]
sort()
[0]
Length
A math expert knows that the area of a circle is PI * the radius squared. However, that
math expert does not know how to code that formula in JavaScript. Using the dropdown
list, fill in the missing code to complete this calculation. - Correct Answers -Math.PI *
Math.pow(radius, 2);
The following code example is almost complete. It just needs comment marks applied to
the areas designated as comments. Using the dropdown arrows, add the correct
comment symbols to finish this code. - Correct Answers -//
/*
*/
You have an external JavaScript file called calculations, located in the scripts folder.
Using the dropdown arrow, insert the proper reference to the script within the head
section of the code example. - Correct Answers -<script src="scripts/calculations.js">
</script>
For each proposed variable name, select Yes if the variable name is permissible in
JavaScript or No if it is not. - Correct Answers -alert Msg NO
$alertmsg YES
alertmsg YES
alert NO
alert_msg YES
As part of a car webpage, a developer is building cars as objects. Each car has multiple
properties. Using the dropdown arrows, fill in the code pieces necessary to build an
TESTING MODE
You have entered the following code into a webpage: <script> function incQty (field)
{ var qty document.getElementById(field).value; qty ++
document.getElementById(field).value qty; } function decQty (field) { qty
document.getElementById(field).value } qt - Correct Answers -Move the qty variable
above the incQty function
Declare the qty variable in the decQty function
You are building a website for a fitness company. You need to display a list of program
dates based on a start date and an end date. You need to build a loop that adds each
date to a bulleted list inside of an element called programList. The start and end dates
are seven days apart, and you need to show all dates in between the start and end
dates. The start date should always display. Using drag and drop, drag over the correct
code snippets in the proper order to build a loop of dates. Any needed variables have
already been declared. Not all options will be used. - Correct Answers -line 1
do {
line 2
document.getElement Byld("programList").in nerHTML += "<li>" + programDate + "
</li>";
line 3
programDate.setDate( programDate.getDate(( ) + 2);
line 4
}
line 5
while (programDate < programEndDate)
You are trying to fill a variable called activity with an activity based on the weather. The
activity to do will be based on the following scenarios: If it is at least 70 degrees and the
weather is clear, the activity will be golf. If it is less than 50 degrees or the weather is
not clear, the activity will be bowling. Otherwise, the activity is hiking. Drag the correct
operators into the missing code slots to finish building this code example. Not every
operator will be used. - Correct Answers -1)>=
, 2)&&
3)==
4)<
5)||
6)!=
You want to store a list of locations in an array, sorted in alphabetical order. You also
want an empty array for new locations, with the intention that the array is filled in with
new locations as needed. Using the dropdown lists, fill in the proper code to declare
both a filled array to the variable, locations, and an empty array to the variable
newLocations. Then, add the code for alphabetizing the locations array before it is
displayed and fill in the code that will make HQ the first element in the array. Finally,
add the code necessary to assign the number of elements in the array to the variable
numberOfLocations. Use the comments to help guide you as to where to add code for
each task. - Correct Answers -[
[]
sort()
[0]
Length
A math expert knows that the area of a circle is PI * the radius squared. However, that
math expert does not know how to code that formula in JavaScript. Using the dropdown
list, fill in the missing code to complete this calculation. - Correct Answers -Math.PI *
Math.pow(radius, 2);
The following code example is almost complete. It just needs comment marks applied to
the areas designated as comments. Using the dropdown arrows, add the correct
comment symbols to finish this code. - Correct Answers -//
/*
*/
You have an external JavaScript file called calculations, located in the scripts folder.
Using the dropdown arrow, insert the proper reference to the script within the head
section of the code example. - Correct Answers -<script src="scripts/calculations.js">
</script>
For each proposed variable name, select Yes if the variable name is permissible in
JavaScript or No if it is not. - Correct Answers -alert Msg NO
$alertmsg YES
alertmsg YES
alert NO
alert_msg YES
As part of a car webpage, a developer is building cars as objects. Each car has multiple
properties. Using the dropdown arrows, fill in the code pieces necessary to build an