Web Programming Practice Test

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Trunkz0r
T
Trunkz0r
Community Contributor
Quizzes Created: 3 | Total Attempts: 1,459
Questions: 40 | Attempts: 554

SettingsSettingsSettings
Web Programming Practice Test - Quiz

.


Questions and Answers
  • 1. 

    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?

    • A.

      A null value

    • B.

      A Boolean value

    • C.

      A Boolean value

    • D.

      A string value

    Correct Answer
    D. A string value
    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.

    Rate this question:

  • 2. 

    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."); }

    • A.

      Please enter your first name:

    • B.

      You must enter your first name.

    • C.

      First name is required.

    • D.

      Thank you.

    Correct Answer
    B. You must enter your first name.
    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.

    Rate this question:

  • 3. 

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

    • A.

      The value property

    • B.

      The checked property

    • C.

      The selected property

    • D.

      The radio property

    Correct Answer
    B. The checked property
    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.

    Rate this question:

  • 4. 

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

    • A.

      The value property

    • B.

      The text property

    • C.

      The name property.

    • D.

      The string property.

    Correct Answer
    A. The value property
    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.

    Rate this question:

  • 5. 

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

    • A.

      The focus method

    • B.

      The blur method

    • C.

      The remove method

    • D.

      The value method

    Correct Answer
    B. The blur method
    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.

    Rate this question:

  • 6. 

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

    • A.

      The click event

    • B.

      The dblclick event

    • C.

      The change event

    • D.

      The select event

    Correct Answer
    C. The change event
    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.

    Rate this question:

  • 7. 

    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; }

    • A.

      Attached to the onload event of the global window object.

    • B.

      Attached to the onload event of a control with an id of “investment”.

    • C.

      Attached to the onchange event of the global window object.

    • D.

      Attached to the onchange event of a control with an id of “investment”.

    Correct Answer
    D. Attached to the onchange event of a control with an id of “investment”.
    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.

    Rate this question:

  • 8. 

    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?

    • A.

      The message property

    • B.

      The text property

    • C.

      The value property

    • D.

      The nodeValue property

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

    Rate this question:

  • 9. 

    Assuming you have a radio button with an id of “contact_via”, which of the following statements selects that radio button?

    • A.

      $("contact_via").selected = true;

    • B.

      $("contact_via").checked = true;

    • C.

      $("contact_via").value = true;

    • D.

      $("contact_via").value = true;

    Correct Answer
    B. $("contact_via").checked = true;
    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.

    Rate this question:

  • 10. 

    How can you clear a check from a Checkbox object?

    • A.

      Set its clear property to true

    • B.

      Set its checked property to false

    • C.

      Set its value property to an empty string

    • D.

      Set its value property to an empty string

    Correct Answer
    B. Set its checked property to false
    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.

    Rate this question:

  • 11. 

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

    Correct Answer
    MAX_VALUE
    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.

    Rate this question:

  • 12. 

    In JavaScript, _________ represents a value that isn’t a valid number.

    Correct Answer
    Number.NaN
    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.

    Rate this question:

  • 13. 

    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.

    Correct Answer
    random
    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.

    Rate this question:

  • 14. 

    The _________ property of a string returns the number of characters in the string.

    Correct Answer
    length
    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.

    Rate this question:

  • 15. 

    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.

    Correct Answer
    getMonth()
    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.

    Rate this question:

  • 16. 

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

    • A.

      NaN

    • B.

      -NaN

    • C.

      Infinity

    • D.

      -Infinity

    Correct Answer
    C. Infinity
    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.

    Rate this question:

  • 17. 

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

    • A.

      The toString method

    • B.

      The round method

    • C.

      The toPrecision method

    • D.

      The toFixed method

    Correct Answer
    D. The toFixed method
    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.

    Rate this question:

  • 18. 

    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";

    • A.

      Count

    • B.

      1

    • C.

      Errors

    • D.

      Error

    Correct Answer
    C. Errors
    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.

    Rate this question:

  • 19. 

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

    • A.

      The Math.max method

    • B.

      The Math.ceil method

    • C.

      The Math.pow method

    • D.

      The Math.abs method

    Correct Answer
    A. The Math.max method
    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.

    Rate this question:

  • 20. 

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

    • A.

      The file is in C:\My Documents

    • B.

      The file is in "C:\My Documents"

    • C.

      The file is in C:\\My Documents\

    • D.

      The file is in "C:\\My Documents\"

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

    Rate this question:

  • 21. 

    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.

    Correct Answer
    identity
    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.

    Rate this question:

  • 22. 

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

    Correct Answer
    >=
    greater than or equal to
    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.

    Rate this question:

  • 23. 

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

    Correct Answer
    &&
    AND
    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.

    Rate this question:

  • 24. 

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

    Correct Answer
    !
    NOT
    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.

    Rate this question:

  • 25. 

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

    Correct Answer
    do-while
    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.

    Rate this question:

  • 26. 

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

    Correct Answer
    for
    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.

    Rate this question:

  • 27. 

    Which of the following operators does NOT perform type coercion?

    • A.

      >

    • B.

      >==

    • C.

      ===

    • D.

      !=

    Correct Answer
    C. ===
    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.

    Rate this question:

  • 28. 

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

    • A.

      "apple" > "orange"

    • B.

      False == "false"

    • C.

      False === 0

    • D.

      "" == 0

    Correct Answer
    D. "" == 0
    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.

    Rate this question:

  • 29. 

    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."); }

    • A.

      Rate is not a number.

    • B.

      Rate is not a number.

    • C.

      Rate cannot be greater than 20%.

    • D.

      Rate is valid.

    Correct Answer
    D. 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."

    Rate this question:

  • 30. 

    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."); }

    • A.

      Loan approved.

    • B.

      Cosigner needed.

    • C.

      Two cosigners needed.

    • D.

      Loan denied.

    Correct Answer
    C. Two cosigners needed.
    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."

    Rate this question:

  • 31. 

    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.

    • A.

      The message property

    • B.

      The text property

    • C.

      The value property

    • D.

      The nodeValue property

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

    Rate this question:

  • 32. 

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

    • A.

      $("contact_via").selected = true;

    • B.

      $("contact_via").checked = true;

    • C.

      $("contact_via").value = true;

    • D.

      $("contact_via").enabled = true;

    Correct Answer
    B. $("contact_via").checked = true;
    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.

    Rate this question:

  • 33. 

    How can you clear a check from a Checkbox object?

    • A.

      Set its clear property to true

    • B.

      Set its checked property to false

    • C.

      Set its value property to an empty string.

    • D.

      Call its blur method

    Correct Answer
    B. Set its checked property to false
    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.

    Rate this question:

  • 34. 

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

    • A.

      The charAt method

    • B.

      The search method

    • C.

      The indexOf method

    • D.

      The substring method

    Correct Answer
    C. The indexOf method
    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.

    Rate this question:

  • 35. 

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

    • A.

      Var birthday = "12/2/1978";

    • B.

      Var birthday = new Date();

    • C.

      Var birthday = new Date("12/2/1978");

    • D.

      Var birthday = new Date(1978, 11, 2);

    Correct Answer
    A. Var birthday = "12/2/1978";
    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)".

    Rate this question:

  • 36. 

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

    • A.

      The getMonth method

    • B.

      The getDate method

    • C.

      The getDay method

    • D.

      The getDayOfMonth method

    Correct Answer
    B. The getDate method
    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.

    Rate this question:

  • 37. 

    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)); }

    • A.

      Investment is not valid.

    • B.

      Investment: $100

    • C.

      Investment: $100.00

    • D.

      Investment: 100.00

    Correct Answer
    A. Investment is not valid.
    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.

    Rate this question:

  • 38. 

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

    • A.

      NaN

    • B.

      53.937

    • C.

      53.94

    • D.

      53.93

    Correct Answer
    C. 53.94
    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.

    Rate this question:

  • 39. 

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

    • A.

      Text1 = text2

    • B.

      Text1 == text2

    • C.

      Text1.toLowerCase() = text2.toLowerCase()

    • D.

      Text1.toLowerCase() == text2.toLowerCase()

    Correct Answer
    D. Text1.toLowerCase() == text2.toLowerCase()
    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.

    Rate this question:

  • 40. 

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

    • A.

      Due_date.setMonth(1);

    • B.

      Due_date.setMonth(2);

    • C.

      Due_date.setMonth("Feb");

    • D.

      Due_date.setMonth("February");

    Correct Answer
    A. Due_date.setMonth(1);
    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.

    Rate this question:

Quiz Review Timeline +

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
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.