Web Programming Practice Test

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Trunkz0r
T
Trunkz0r
Community Contributor
Quizzes Created: 3 | Total Attempts: 1,481
| Attempts: 565 | Questions: 40
Please wait...
Question 1 / 40
0 %
0/100
Score 0/100
1. The _________ property of a string returns the number of characters in the string.

Explanation

The "length" property of a string is used to determine the number of characters present in the string. It returns the total count of characters, including spaces and punctuation marks. This property is commonly used in programming to manipulate and analyze strings based on their length.

Submit
Please wait...
About This Quiz
Web Programming Practice Test - Quiz

This Web Programming Practice Test is designed to assess your understanding of JavaScript interactions in web environments, focusing on dialog boxes, form controls, and event handling. It's ideal... see morefor learners aiming to enhance their web development skills. see less

2. The ________________ loop is typically used when the loop requires a counting variable.

Explanation

The "for" loop is typically used when the loop requires a counting variable. It allows for the initialization of a variable, a condition to be checked before each iteration, and an increment or decrement of the variable after each iteration. This makes it ideal for situations where a loop needs to iterate a specific number of times or when a loop needs to iterate over a sequence of elements using an index.

Submit
3. The ___________ operator returns a true value if the expression on its left is greater than or equal to the expression on its right.

Explanation

The >= operator is used to compare two expressions and returns true if the expression on its left is greater than or equal to the expression on its right. It is commonly used in conditional statements to check if a value is greater than or equal to another value.

Submit
4. The ____________ method of the Math object can be used to generate and return a decimal number that's greater than or equal to 0 but less than 1.

Explanation

The "random" method of the Math object generates and returns a decimal number between 0 (inclusive) and 1 (exclusive). This means that the number can be greater than or equal to 0 but less than 1.

Submit
5. The ___________ operator returns a true value when the expression on both sides of the operator are true.

Explanation

The "&&" operator is also known as the "AND" operator. It returns a true value only when both sides of the operator are true. In other words, if the expression on the left side and the expression on the right side of the "&&" operator are both true, then the overall result will be true. If either one or both of the expressions are false, then the overall result will be false.

Submit
6. The ________________ operator has the highest precedence of the logical operators.

Explanation

The "!" operator, also known as the "NOT" operator, has the highest precedence among all the logical operators. This means that when evaluating an expression, the "!" operator is applied first before any other logical operators.

Submit
7. The ________________ loop tests its conditional expression at the end of the loop.

Explanation

The do-while loop is a type of loop that tests its conditional expression at the end of the loop. This means that the code within the loop will always execute at least once, regardless of whether the condition is initially true or false. After the code has executed, the condition is checked and if it is true, the loop will continue to execute. If the condition is false, the loop will terminate and the program will move on to the next line of code.

Submit
8. What method of the Math object can be used to return the largest value from the values that are passed to it?

Explanation

The Math.max method is used to return the largest value from the values that are passed to it. This method takes multiple arguments and returns the highest value among them. It is commonly used in mathematical calculations or when comparing multiple values to find the maximum value.

Submit
9. The _______ property of the Number object returns the largest positive value that JavaScript can represent.

Explanation

The MAX_VALUE property of the Number object in JavaScript returns the largest positive value that can be represented by the language. It is a constant value that can be used to compare or set the maximum limit for numerical operations in JavaScript.

Submit
10. Which of the following statements is NOT a valid way to create a date object named birthday?

Explanation

The statement "var birthday = "12/2/1978";" is not a valid way to create a date object named birthday because it assigns a string value to the variable instead of a date object. The other options correctly create a date object using different methods: assigning the current date and time using "new Date()", parsing a string date using "new Date("12/2/1978")", and specifying the year, month, and day as arguments using "new Date(1978, 11, 2)".

Submit
11. What property of the Radio object is used to determine if a radio button is selected?

Explanation

The correct answer is the checked property. This property is used to determine if a radio button is selected. It returns a boolean value, true if the radio button is selected and false if it is not.

Submit
12. For a Textarea object, what property do you use to get the text that has been entered into the text area?

Explanation

The value property is used to get the text that has been entered into the textarea. This property allows you to access and retrieve the content of the textarea element.

Submit
13. The equality operators convert data from one type to another before performing a comparison, but the ______________ operators do not convert data before performing a comparison.

Explanation

The identity operators in programming, such as "===" in JavaScript, do not convert data types before performing a comparison. They strictly check for both value and type equality. This means that the operands must be of the same type and have the same value for the comparison to be true. In contrast, the equality operators like "==" in JavaScript, will perform type conversion if the operands are of different types before making the comparison.

Submit
14. Assuming you have a radio button with an id of "contact_via", which of the following statements selects that radio button?

Explanation

The correct statement that selects the radio button with an id of "contact_via" is $("contact_via").checked = true;. This statement uses the checked property to set the radio button as selected.

Submit
15. How can you clear a check from a Checkbox object?

Explanation

To clear a check from a Checkbox object, you need to set its checked property to false. This will uncheck the checkbox and remove the check mark from it.

Submit
16. Assuming you have a radio button with an id of "contact_via", which of the following statements selects that radio button?

Explanation

The correct statement that selects the radio button with the id "contact_via" is $("contact_via").checked = true;. This statement sets the "checked" property of the radio button to true, which selects the radio button.

Submit
17. What text does the following code display in the dialog box? var investment = "$100"; if (isNaN(investment) || investment <= 0) {          alert("Investment is not valid"); } else {           alert("Investment: " + investment.toFixed(2)); }

Explanation

The code will display "Investment is not valid" in the dialog box. This is because the variable "investment" is assigned the value "$100", which is a string. The code checks if the investment is not a number (isNaN) or if it is less than or equal to 0. Since "$100" is not a number, the condition is true and the alert message "Investment is not valid" is displayed.

Submit
18. To remove the focus from a control, what method do you use?

Explanation

The blur method is used to remove the focus from a control. When a control has focus, it means that it is currently selected or active, and the blur method allows you to shift the focus away from that control. This can be useful in situations where you want to redirect the user's attention to another part of the page or remove the focus from a specific control after a certain event or action has occurred.

Submit
19. Given a Date object named due_date, which of the following statements sets the month to February?

Explanation

The correct answer is due_date.setMonth(1). In JavaScript, the setMonth() method is zero-based, which means that January is represented by 0, February by 1, and so on. Therefore, calling setMonth(1) will set the month of the due_date object to February.

Submit
20. The _____________ method of a Date object returns the month in local time with a value of 0 for January, 1 for February, and so on.

Explanation

The getMonth() method of a Date object returns the month in local time with a value of 0 for January, 1 for February, and so on. This method is used to retrieve the month component of a date object. It is useful when you need to perform operations or comparisons based on the month value.

Submit
21. How can you clear a check from a Checkbox object?

Explanation

To clear a check from a Checkbox object, you need to set its checked property to false. This will uncheck the checkbox and remove the checkmark from it.

Submit
22. If a numerical operation returns a number greater than the largest possible JavaScript value, it returns

Explanation

If a numerical operation in JavaScript returns a number that is greater than the largest possible JavaScript value, it will return "Infinity". This occurs when a calculation exceeds the maximum value that can be represented in JavaScript, which is approximately 1.7976931348623157e+308. "Infinity" represents an infinite value and is used to indicate that the result of the operation is beyond the numeric limits of JavaScript.

Submit
23. What method of the Date object gets the day of the month in local time?

Explanation

The correct answer is the getDate method. This method returns the day of the month in local time. It is used to retrieve the numerical value of the day of the month from a Date object.

Submit
24. Which of the following operators does NOT perform type coercion?

Explanation

The operator "===" does not perform type coercion. It is a strict equality operator that checks for both value and type equality. It returns true if the operands are of the same type and have the same value, and false otherwise. Unlike the "==" operator, which performs type coercion and converts the operands to a common type before comparison, the "===" operator does not perform any type coercion and requires both operands to be of the same type for a true result.

Submit
25. For the following code, if the user clicks the Cancel button in the first dialog box that's displayed, a second dialog box is displayed that says... var firstName = prompt("Please enter your first name:"); if ( firstName  == null ) {     alert("You must enter your first name."); } else if (firstName == "") {     alert("First name is required."); } else {     alert("Thank you."); }

Explanation

The correct answer is "You must enter your first name." because if the user clicks the Cancel button in the first dialog box, the value of the variable firstName will be null. The first if statement checks if the value of firstName is null, and if it is, it displays the alert message "You must enter your first name." This is the correct answer because it accurately describes the action taken when the Cancel button is clicked.

Submit
26. What event occurs when the user selects a new item from a select list?

Explanation

When the user selects a new item from a select list, the event that occurs is the change event. This event is triggered when the value of the select list is changed, indicating that the user has made a selection. It allows for the execution of specific actions or functions in response to the user's selection.

Submit
27. If the count variable has a value of 1, what is the value of the test variable after the following statement is executed? var test = (count == 1) ? "errors" : "error";

Explanation

The value of the test variable will be "errors" if the count variable has a value of 1. This is because the ternary operator is used in the statement, which checks if the condition (count == 1) is true. If it is true, the value "errors" is assigned to the test variable. If the condition is false, the value "error" is assigned to the test variable. Since the count variable has a value of 1, the condition is true and "errors" is assigned to the test variable.

Submit
28. What is displayed when the following code executes? var age = 19, score = 750; if ( age >= 21 && score >= 700 ) {     alert ("Loan approved"); } else if ( age >= 21 && score >= 650 ) {     alert ("Cosigner needed."); } else if ( age >= 18 && score >= 680 ) {     alert ("Two cosigners needed."); } else {     alert ("Loan denied."); }

Explanation

The code first checks if the age is greater than or equal to 21 and the score is greater than or equal to 700. Since the age is 19 and the score is 750, this condition is not met. Then it checks if the age is greater than or equal to 21 and the score is greater than or equal to 650. Again, this condition is not met. Next, it checks if the age is greater than or equal to 18 and the score is greater than or equal to 680. This condition is also not met. Finally, since none of the conditions are met, the code executes the else statement and displays "Loan denied." Therefore, the correct answer is "Loan denied."

Submit
29. What is the value of salesTax after the following code executes? var salesTax = 53.937; salesTax = parseFloat(salesTax.toFixed(2));

Explanation

The code first uses the toFixed() method to round the value of salesTax to 2 decimal places, resulting in 53.94. Then, the parseFloat() function is used to convert the rounded value back to a floating-point number. Therefore, the value of salesTax after the code executes is 53.94.

Submit
30. If the prompt method displays a dialog box, and the user enters some text and clicks on the OK button, what does the prompt method return?

Explanation

The prompt method returns a string value. When the user enters text and clicks on the OK button in the dialog box, the prompt method captures that text and returns it as a string value.

Submit
31. What method of the String object searches the string for an occurence of the specified search string?

Explanation

The indexOf method is used to search for the first occurrence of a specified search string within a given string. It returns the index of the first occurrence of the search string, or -1 if the search string is not found.

Submit
32. What is displayed when the following code executes? var rate = 0.1; if ( isNaN(rate) ) {     alert("Rate is not a number."); } else if (rate < 0) {     alert("Rate cannot be less than zero."); } else if (rate > 0.2) {     alert("Rate cannot be greater than 20%."); } else {     alert("Rate is valid."); }

Explanation

The code first checks if the value of the variable "rate" is not a number using the isNaN() function. Since the value of "rate" is a number (0.1), this condition is false. Then it checks if the value of "rate" is less than 0, which is also false. Next, it checks if the value of "rate" is greater than 0.2, which is also false. Since none of the previous conditions are true, the code executes the else block and displays the message "Rate is valid."

Submit
33. In JavaScript, _________ represents a value that isn't a valid number.

Explanation

In JavaScript, Number.NaN represents a value that isn't a valid number. It is a special value that indicates the result of an operation that cannot produce a normal numeric result. It is often used to check if a value is not a number using the isNaN() function.

Submit
34. What method of the Number object returns a string with the number rounded to the specified number of decimal places?

Explanation

The toFixed method of the Number object returns a string with the number rounded to the specified number of decimal places. This method is used to format a number with a fixed number of decimal places, regardless of whether there are trailing zeros. It allows for precise control over the number of digits displayed after the decimal point.

Submit
35. To display data in a span element, you can use the firstChild property to get a pointer to the Text node. Then, what property of the Text node can you use to set the value that's displayed in the span element?

Explanation

The correct property to set the value that's displayed in the span element is the nodeValue property.

Submit
36. To display data in a span element, you can use the firstChild property to get a pointer to the Text node.  Then, what property of the Text node can you use to set the value that's displayed in the span element.

Explanation

The correct answer is the nodeValue property. The nodeValue property is used to set the value that is displayed in the span element.

Submit
37. Which of the following statements performs a case-insensitive comparison of strings named text1 and text2?

Explanation

The correct answer is "text1.toLowerCase() == text2.toLowerCase()". This statement performs a case-insensitive comparison of the strings named text1 and text2 by converting both strings to lowercase using the toLowerCase() method and then comparing them using the equality operator (==). This ensures that the comparison is not affected by differences in letter case.

Submit
38. Which of the following comparisons will result in a true value?

Explanation

The comparison "" == 0 will result in a true value. This is because the double equals operator (==) in JavaScript performs type coercion, which means it converts the operands to a common type before comparison. In this case, an empty string "" is coerced to a numerical value of 0, and since both operands now have the same type (number), the comparison evaluates to true.

Submit
39. For the following code, an event handler named investment_change is var investment_change = function () {     var years = parseInt( $("years").value );     alert("Years: " + years); }   window.onload = function () {     $("investment").onchange = investment_change; }

Explanation

The event handler named investment_change is attached to the onchange event of a control with an id of "investment". This means that the code will be executed whenever the value of the control with the id "investment" is changed.

Submit
40. What text does the following code display in a dialog box? alert("The file is in \"C:\\My Documents\"");

Explanation

The code displays the text "The file is in "C:\My Documents\" in a dialog box.

Submit
View My Results

Quiz Review Timeline (Updated): Nov 16, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Nov 16, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Oct 15, 2013
    Quiz Created by
    Trunkz0r
Cancel
  • All
    All (40)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
The _________ property of a string returns the number of characters in...
The ________________ loop is typically used when the loop requires a...
The ___________ operator returns a true value if the expression on its...
The ____________ method of the Math object can be used to generate and...
The ___________ operator returns a true value when the expression on...
The ________________ operator has the highest precedence of the...
The ________________ loop tests its conditional expression at the end...
What method of the Math object can be used to return the largest value...
The _______ property of the Number object returns the largest positive...
Which of the following statements is NOT a valid way to create a date...
What property of the Radio object is used to determine if a radio...
For a Textarea object, what property do you use to get the text that...
The equality operators convert data from one type to another before...
Assuming you have a radio button with an id of "contact_via", which of...
How can you clear a check from a Checkbox object?
Assuming you have a radio button with an id of...
What text does the following code display in the dialog box? ...
To remove the focus from a control, what method do you use?
Given a Date object named due_date, which of the following statements...
The _____________ method of a Date object returns the month in local...
How can you clear a check from a Checkbox object?
If a numerical operation returns a number greater than the largest...
What method of the Date object gets the day of the month in local...
Which of the following operators does NOT perform type coercion?
For the following code, if the user clicks the Cancel button in the...
What event occurs when the user selects a new item from a select list?
If the count variable has a value of 1, what is the value of the test...
What is displayed when the following code executes? ...
What is the value of salesTax after the following code executes? ...
If the prompt method displays a dialog box, and the user enters some...
What method of the String object searches the string for an occurence...
What is displayed when the following code executes? ...
In JavaScript, _________ represents a value that isn't a valid number.
What method of the Number object returns a string with the number...
To display data in a span element, you can use the firstChild property...
To display data in a span element, you can use the firstChild property...
Which of the following statements performs a case-insensitive...
Which of the following comparisons will result in a true value?
For the following code, an event handler named investment_change is ...
What text does the following code display in a dialog box? ...
Alert!

Advertisement