AJAX Assessment
See the comments for instructions
HTML
<script src="//code.jquery.com/qunit/qunit-1.15.0.js"></script>
<link rel="stylesheet" href="//code.jquery.com/qunit/qunit-1.15.0.css">
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
</body>
JavaScript
//Name: Your Name Here
//Date: 00/00/00
/*
* Please be sure to hit the Fork button at the top before you begin
working to ensure we can locate your solution.
* Hit update when done and send the new url.
* Write a function, fillCart, that does the following:
* Accepts a shoppingList as a comma-delimited list of item names
to get, and a callback to be used once all the items have
been retrieved.
* For each item in the shopping list, it:
* Makes an AJAX request to '/items/:itemName' i.e. '/items/carrots'
* Creates an Item object from the JSON returned by the AJAX request
* Puts that Item into an array, in the order of the original
shopping list
* Once it has the data for all items in the shopping list,
it calls completeCallback, passing completeCallback the array
of Items.
* jQuery 1.11.0 available
* AJAX requests may take different amounts of time
* Item constructor defined below
*/
function fillCart(shoppingList, completeCallback) {
shoppingList.split(",").reduce(function(resultPromise, shoppingItem) {
return resultPromise.then(function(result) {
return $.ajax('/items/'+shoppingItem).then(function(res) {
result.push(new Item(res.label,res.price));
return result;
});
});
}, $.when([])).then(completeCallback);
}
/* Don't edit below this line.*/
/*
* Item constructor function
*/
function Item(name, price) {
this.name = name;
this.price = price;
}
//The code should pass these tests.
(function(){
var itemsRequested = 0;
QUnit.config.testTimeout = 10000;
QUnit.asyncTest("Simple Ajax Testing", function (assert) {
expect(7);
//This lets the AJAX URL work on JSFiddle. Don't worry about it.
$.ajaxPrefilter(ajaxfilter);
var list = "carrots,milk,eggs,bread,trash bags,salt";
var originalList =...