PdfPrep.com

How should you complete the relevant code?

DRAG DROP

A company asks you to create a function that displays loan amounts to their customers.

You must create the function by using JavaScript to meet the following requirements:

• Display three different loan amounts to each customer.

• Display loan amounts in order starting with the greatest amount and ending with the least amount.

You need to implement the function.

How should you complete the relevant code? (To answer, drag the appropriate command or commands to the correct location or locations in the answer area. Use only commands that apply.)

Answer:

Explanation:

* The innermost assignment to the loanAmount variable should be the highest.

* Local variables have local scope: They can only be accessed within the function.

Example

// code here can not use carName

function myFunction() {

var carName = "Volvo";

// code here can use carName

}

* A variable declared outside a function, becomes GLOBAL.

A global variable has global scope: All scripts and functions on a web page can access it.

Example

var carName = " Volvo";

// code here can use carName

function myFunction() {

// code here can use carName

}

* The alert () method displays an alert box with a specified message and an OK button.

An alert box is often used if you want to make sure information comes through to the user.

Reference: JavaScript Scope

Exit mobile version