Which code segment or segments should you use?

DRAG DROP
You are developing an application for an online retailer. The company ships only to certain countries.
The application must:
Store a list of country codes in an array
Validate the country code of the shipping address against the countries array
Include a Boolean value in the array that indicateswhether or not you can ship to the country
Display a list of countries that can be shipped to if the user inputs a code for a country that the retailer cannot
ship to
You need to develop the application to meet the requirements.
Which code segment or segments should you use? (To answer, drag the appropriate code segment or segments from the list of code segments to the correct location or locations in the work area. Each code segment may be used once, more than once, or not atall. You may need to drag the split bar between panes or scroll to view content.)

DRAG DROP
You are developing an application for an online retailer. The company ships only to certain countries.
The application must:
Store a list of country codes in an array
Validate the country code of the shipping address against the countries array
Include a Boolean value in the array that indicateswhether or not you can ship to the country
Display a list of countries that can be shipped to if the user inputs a code for a country that the retailer cannot
ship to
You need to develop the application to meet the requirements.
Which code segment or segments should you use? (To answer, drag the appropriate code segment or segments from the list of code segments to the correct location or locations in the work area. Each code segment may be used once, more than once, or not atall. You may need to drag the split bar between panes or scroll to view content.)

A.

B.

C.

D.

Explanation:



Leave a Reply 3

Your email address will not be published. Required fields are marked *


Salento

Salento

I think that the answer is wrong:
– the statement “for (var i in arr)” loops over the properties of an object, it’s better to use “(for i=0; i<arr.length;i++)"
– the question is not clear, "Display a list of countries that can be shipped to ..". UK, that has "false" in the arr, mustn't be displayed; so, in my opinion, the correct answer is the "for" with the "if arr(i)" inside.

Carri

Carri

Check it, arr[0] is undefined.

The array’s index is of type string, so you must use “for (var i in arr)” instead “(for i=0; i<arr.length;i++)" to scan the table.

Ajaz

Ajaz

Validate Country Code

function validate() {
var arr = new Array()
arr[“US”] = true;
arr[“CA”] = true;
arr[“UK”] = false;

var txt = “”;
var ctry = document.getElementById(“Country”).value;
console.log(arr[ctry]);
if (!arr[ctry])
{
txt += “Country is not valid. “;
txt += “Valid value are”;
console.log(arr.length);
for (var i in arr){
if (arr[i])
txt += i + ” “;
}

document.getElementById(“valid”).innerText = txt;
}
}