CIT 171 Chapter 11 Review

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Suppose you want to modify the following JavaScript event handler to use arrow function syntax: form.onclick = function() { console.log("The user clicked the form!"); } ​ What should you place in the blank in the following modified version? form.onclick = _____

() => console.log("The user clicked the form!");

Suppose you are sending a request to the server-side script keywords.pl and expect to receive a list of suggested keywords in JSON format. What belongs in the blank if the then() method calls that are commented out in the following JavaScript code handle the JSON data as an object literal?fetch("keywords.pl?suggest=" + encodeURIComponent(sInput.value))_____// more then() method calls.catch(search.innerHTML = "Error loading data.");

.then(response => response.json())

Which of the following statements is true regarding Cross Origin Resource Sharing (CORS)?

CORS places information within the HTTP message header indicating that transfers of data between different websites are allowed.

Which statement regarding error handling for the following JavaScript statement is correct? fetch("bullfrogStory.html") .then(response => response.text()) .then(text => story.innerHTML = text) .catch(story.innerHTML = "Error loading story.");

Code to handle the condition where the response.ok property evaluates to false should be added.

When both the open() and send() methods have been called on a request object but the client has not yet begun to receive a response to the request, what state is the request object in?

HEADERS_RECEIVED

Which of the following is an AJAX principle described by Jesse James Garrett in 2005?

JSON is the preferred language of data exchange.

Suppose you have constructed four promises—doLaundry, doDishes, cleanCounters, and sweepFloors—and stored them in an array assigned to the variable chores. You want to initiate them all at once because they are independent actions. When all four complete successfully, you want to run the takeNap function, but if any of them fails, you want to run the tryAgain function. Which JavaScript statement should you use to accomplish this?

Promise.all(chores).then(takeNap).catch(tryAgain);

How can you prevent a client from temporarily storing data sent within an HTTP message for later use?

Set the message's Cache-Control header to no-cache.

What does the following HTTP response header indicate to the browser? Connection: close Date: Wed, 26 June 2024 10:11:12 GMT Cache-Control: no-cache

The browser should not store the data it is receiving from the server for later access.

If chooseActivity is a JavaScript promise object that returns a string value, which code should you use to initiate this promise?

chooseActivity.then(choiceMsg => console.log(choiceMsg)).catch(choiceMsg => console.log(choiceMsg));

Suppose you have created a chooseActivity promise object in your JavaScript program. You want to initiate the promise and pass the resulting value to another function if chooseActivity resolves successfully. What code should you write to do this?

chooseActivity.then(choiceMsg => { console.log(choiceMsg); return "Starting warm-up!";}).then(wuMsg => console.log(wuMsg)).catch(choiceMsg => console.log(choiceMsg);

Suppose you have stored the JavaScript promise objects fillPool, setUpSoccerNet, and fillSandbox in an array called outdoorFunPrep. The following code _____. Promise.race(outdoorFunPrep) .then(stayOutside) .catch(goInside);

executes stayOutside when the first of the promises in the array to return something resolves successfully

The following HTML code correctly employees the JSON with Padding approach to manage website data transfer across origins.

false

The following JavaScript code using the bakeCookies promise object will cause one of two possible messages/strings of messages to be written to the console.let bakeCookies = new Promise( (resolve, reject) => {setTimeout( ()=>if (Math.random() < 0.8)resolve("Cookies are baking.")} else {reject("Oops... out of flour.");}}, 2000);});bakeCookies.then(msg => {console.log(msg);return new Promise( (resolve, reject) => {setTimeout( () => {if (Math.random() < 0.9) {resolve("Yummy cookies!");} else {reject("Oh, no! Burned cookies.");}}, 1000);});}).then(msg2 => console.log(msg2)).catch(msg => console.log(msg));

false

The following JavaScript line, which is intended to send a GET request to a Perl server script, is correctly written. Assume that the searchBox element allows the user to enter a text string.fetch("archives.pl?skey=" + searchBox.value)

false

The following JavaScript statements can be used to retrieve a random image related to pizza from Giphy and then use it on a website.let url = "https://api.giphy.com/v1/gifs/trending";fetch(`${url}?tag=pizza&limit=1&rating=g`).then(response => response.json())// more .then method calls.catch(console.log("Error loading data."));

false

To use the proxy server approach to handle requests to third-party APIs, you must set up your own proxy server, then use an AJAX request object or Fetch to make the request of the proxy server.

false

You can convert data requested with the fetch() method and returned from a server in JSON format into a JavaScript object literal by passing in the response from the server to the new JSON() object constructor.

false

Which JavaScript statement asynchronously makes a GET request from the frogs.pl file on the server?

fetch("frogs.pl&id=bull443")

Suppose you are writing JavaScript code to send an asynchronous GET request to the action.pl file on the server. You have instantiated an XHR object and saved it to the variable httpReq. Which statement should you use to begin the request?

httpReq.open("get", "action.pl&id=41088");

Suppose you are writing JavaScript code to send an asynchronous GET request to the action.pl file on the server. You have written code that defines your request. Which statement should you use next to send it to the server?

httpReq.send(null);

Suppose you want to write a message to the console to indicate whether or not the server's response to the request sent using the httpReq object is complete. What JavaScript code belongs in the blank? httpReq.onreadystatechange = function() { _____ console.log("Request object state: complete"); { } else { console.log("Request object state: not complete"); } }

if (httpReq.readyState === 4) {

The new Promise() object constructor contains a command block called an executor that includes _____.

includes callback functions that are run once the promise is either resolved or rejected

You are examining a JavaScript program and find a series of nested if statements, each of which includes a test condition that verifies that a request object had a completed response and a successful connection, followed by the instantiation of a new request object. Once the inner if condition is verified, the program calls the open() and send() methods on each successful request object in turn. This situation _____.

is known as callback hell among JavaScript developers

Which JavaScript statement creates an object that can be used to convert XML text into an XML DOM object?

let myConverter = new DOMParser();

Which JavaScript statement should you execute first to enable your program to send asynchronous requests to the server over HTTP?

let myReq = new XMLHttpRequest();

How would you rewrite the following JavaScript function using arrow function syntax?function totalWithTax(price1, price2) {return (price1 + price2) * 1.09;}

let totalWithTax = (price1, price2) => (price1 + price2) * 1.09;

The body of an HTTP message _____.

might contain data the server needs to process a request

Which JavaScript statement can you use to convert the contents of the medicalnews.xml file into a DOM?

new DOMParser().parseFromString("medicalnews.xml", "text/xml");

Asynchronous data transfer between a client and server _____.

occurs each time a browser accesses a page via the HTTP protocol

To request data from a third-party service to use on your website, you will typically need to _____.

pass in the appropriate endpoint and parameters as provided by its API to the fetch() method

When you define a function using arrow function syntax, you _____.

replace the function keyword with the fat arrow symbol, which is placed after the function parameters

What steps, in order, must typically take place to regularly update the content for just one part of a previously loaded web page, such as a newsfeed pane, in an efficient manner?

request to server, request to database, database response, server response

Which method do you call on an XHR object to define an HTTP header, passing in the name and value as arguments?

setRequestHeader()

You can use a function expression to _____.

store a function as a variable

The "network" tab or menu within a browser's developer tools allows you to view request objects in use, the HTTP content of messages, and statistics regarding the time required to manage requests and responses.

true

The HTTP header Access-Control-Allow-Origin: https://fakeapiservice.com authorizes requests from a fully qualified domain that can receive data without hindrance from the browser.

true

To create an autosuggest search box using JavaScript, you can write an event handler that responds to the search box's keyup event, hiding the box that displays search suggestions when there are no printable characters in the search box or requesting a list of matching keywords from the server when the user types printable characters within the search box.

true

When using the Fetch API, server responses are typically processed using a promise chain.

true

When you register to use third-party services, you should expect these services to provide APIs organized by endpoints, which are essentially the URLs to which requests are made and that provide the points of contact between the client device and the service's resources.

true

You can use the fetch() method to send an asynchronous POST request to a server by passing in as arguments the location of the server resource and an options object that includes the method: POST, headers: value, and body: value options to describe the HTTP message.

true

RSS newsfeeds _____.

typically require parsing into an XML DOM object and conversion into an HTML structure before they are used in a web page

Suppose you are working on JavaScript code for a web app that sends asynchronous requests to the server. Your program should run a function to process the value of the responseText property of the request object only when its status property is _____.

within the range of 200 to 299


संबंधित स्टडी सेट्स

psc 124 quiz #4 Terms Chapters 10 and 7

View Set

PrepU Chapter 41: Management of Patients with Intestinal and Rectal Disorders

View Set

Questions from text chapter 9 (strings)

View Set

Microbial Metabolism: Fueling Cell Growth

View Set