Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JavaScript Question 19 (1 point) Code Example 4-2 var add = function( x, y ) { r

ID: 3891138 • Letter: J

Question

JavaScript

Question 19 (1 point)

Code Example 4-2
var add = function( x, y ) {
    return ( x + y );
}
alert( add (5, 3) );

(Refer to Code Example 4-2) The function in this example

Question 19 options:

accepts 2 parameters and returns 2 values

accepts 2 parameters and returns 1 value

accepts 2 parameters and does not return a value

does not accept a parameter and returns 1 value

Save

Question 20 (1 point)

Code Example 4-2
var add = function( x, y ) {
    return ( x + y );
}
alert( add (5, 3) );

(Refer to Code Example 4-2) The alert method in this example

Question 20 options:

displays a dialog box with a value of 8

displays a dialog box with a value of 5, 3

displays a dialog box with a value of x + y

does not display a dialog box

Save

Question 21 (1 point)

Code Example 4-3
var tax = .07;
var getCost = function(itemCost, numItems) {
      var subtotal = itemCost * numItems;
      var tax = 0.06;
      var total = subtotal + subtotal * tax;
      return (total);
}
var totalCost = getCost(25.00, 3);
alert("Your cost is $" + totalCost.toFixed(2) + " including a tax of " +
          tax.toFixed(2));

(Refer to Code Example 4-3) Which variable represents the function expression?

Question 21 options:

totalCost

getCost

itemCost

total

Save

Question 22 (1 point)

Code Example 4-3
var tax = .07;
var getCost = function(itemCost, numItems) {
      var subtotal = itemCost * numItems;
      var tax = 0.06;
      var total = subtotal + subtotal * tax;
      return (total);
}
var totalCost = getCost(25.00, 3);
alert("Your cost is $" + totalCost.toFixed(2) + " including a tax of " +
          tax.toFixed(2));

(Refer to Code Example 4-3) What is the value of the global variable, tax?

Question 22 options:

.07

.06

4.5

5.25

Save

Question 23 (1 point)

Code Example 4-3
var tax = .07;
var getCost = function(itemCost, numItems) {
      var subtotal = itemCost * numItems;
      var tax = 0.06;
      var total = subtotal + subtotal * tax;
      return (total);
}
var totalCost = getCost(25.00, 3);
alert("Your cost is $" + totalCost.toFixed(2) + " including a tax of " +
          tax.toFixed(2));

(Refer to Code Example 4-3) This code contains an error. Identify the error.

Question 23 options:

You cannot include two different values for the same variable in one program.

You cannot use the toFixed() method with the result of a function call.

The alert will display an incorrect value for the tax rate.

Parameters passed to a function must be variables, not literal values.

Save

Question 24 (1 point)

Which of the following is NOT true about the script mode feature of ECMAScript 5?

Question 24 options:

Script mode addresses the problem of creating unwanted variables when the var keyword is omitted or when an identifier has been misspelled.

To use script mode you add the “use strict” directive at the top of a file or function.

Script mode is supported by all older browsers.

If the var keyword is omitted, script mode will cause the JavaScript engine to stop running the code.

Save

Question 25 (1 point)

To attach an event handler to an event (such as a user clicking a button), you

Question 25 options:

specify the action to be taken

use a function declaration that is automatically called when an event occurs

specify the object and the event that triggers the event handler

can do any of the above

Save

Question 26 (1 point)

What will happen first as soon as the page that contains the following code loads?
window.onload = function()      {
      alert("Welcome to the Calculate Cost page!");
      $("ship").onclick = shipCost();

};

Question 26 options:

An alert dialog box will display with the message "Welcome to the Calculate Cost page!".

A function with id = "ship" will execute automatically.

The function named shipCost() will execute automatically.

The function named shipCost() will execute when the user clicks on it.

Save

Question 27 (1 point)

Which of the following will create an event handler that is attached to the mouseout event for a textbox with id = "username" so that the user’s entry, formatted in all lowercase, will be displayed in an alert? Assume the following $ function has already been coded in the page:
var $ = function(id)      {
     return document.getElementById(id);

};

Question 27 options:

var getUserName = function()      {
     alert("Your username is " + getUserName.toLowerCase());
};
window.onload = function()      {
     $("username").onmouseout = getUserName;

};

var getUserName = function()      {
     var name = $("username").value;
     alert("Your username is " + name.toLowerCase());
};
window.onload = function()      {
     $("username").onmouseout = getUserName;

};

var getUserName = function()      {
     var name = $("id").value;
     alert("Your username is " + name.toLowerCase());
};
window.onload = function()      {
     $("id").onmouseout = getUserName();

};

var getUserName = function()      {
     var name.toLowerCase() = $("username").value;
     alert("Your username is " + name);
};
window.onload = function()      {
     $("id").onmouseout = getUserName();

};

accepts 2 parameters and returns 2 values

accepts 2 parameters and returns 1 value

accepts 2 parameters and does not return a value

does not accept a parameter and returns 1 value

Explanation / Answer

Please find the answer below:

Question 19 (1 point)

var add = function( x, y ) {

return ( x + y );

}

alert( add (5, 3) );

this function accepts 2 parameters and returns 1 value

Question 20 (1 point)

Code Example 4-2

var add = function( x, y ) {

return ( x + y );

}

alert( add (5, 3) );

it will return addition of 5,3 to alert hence

displays a dialog box with a value of 8

Question 21 (1 point)

Question 21 Unsaved

Code Example 4-3

var tax = .07;

var getCost = function(itemCost, numItems) {

var subtotal = itemCost * numItems;

var tax = 0.06;

var total = subtotal + subtotal * tax;

return (total);

}

var totalCost = getCost(25.00, 3);

alert("Your cost is $" + totalCost.toFixed(2) + " including a tax of " +

tax.toFixed(2));

  

here function assignment goes to getCost hence getCost having function expression

getCost

Question 22 (1 point)

Question 22 Unsaved

Code Example 4-3

var tax = .07;

var getCost = function(itemCost, numItems) {

var subtotal = itemCost * numItems;

var tax = 0.06;

var total = subtotal + subtotal * tax;

return (total);

}

var totalCost = getCost(25.00, 3);

alert("Your cost is $" + totalCost.toFixed(2) + " including a tax of " +

tax.toFixed(2));

tax is defined as global and outside global value will be printed that is : .07

Question 23 (1 point)

Question 23 Unsaved

Code Example 4-3

var tax = .07;

var getCost = function(itemCost, numItems) {

var subtotal = itemCost * numItems;

var tax = 0.06;

var total = subtotal + subtotal * tax;

return (total);

}

var totalCost = getCost(25.00, 3);

alert("Your cost is $" + totalCost.toFixed(2) + " including a tax of " +

tax.toFixed(2));

  

As tax assigned value of .06 inside the function but outside global value will be print that is the error

The alert will display an incorrect value for the tax rate.

Question 24 (1 point) :::

Script mode not supported by some older browsers

Script mode is supported by all older browsers.

Question 25 (1 point):::

Function handler can be added using event and the fucntion needs to be done so ::

Specify the object and the event that triggers the event handler

Question 26 (1 point)::::

window.onload = function() {

alert("Welcome to the Calculate Cost page!");

$("ship").onclick = shipCost();

};

Here alert will come than shipCost function will also get callled

An alert dialog box will display with the message "Welcome to the Calculate Cost page!".

and The function named shipCost() will execute automatically.

Question 27 (1 point):::::

Second option below code will do the same::

var getUserName = function() {

var name = $("username").value;

alert("Your username is " + name.toLowerCase());

};

window.onload = function() {

$("username").onmouseout = getUserName;

};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote