Skip to content

Commit 2fc00a3

Browse files
committed
Switched == equality with === equality.
1 parent 528768f commit 2fc00a3

File tree

1 file changed

+42
-43
lines changed
  • Assignments/version2/module5-solution-starter/js

1 file changed

+42
-43
lines changed

Assignments/version2/module5-solution-starter/js/script.js

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ $(function () { // Same as document.addEventListener("DOMContentLoaded"...
1414
var dc = {};
1515

1616
var homeHtmlUrl = "snippets/home-snippet.html";
17-
var allCategoriesUrl =
17+
var allCategoriesUrl =
1818
"https://davids-restaurant.herokuapp.com/categories.json";
1919
var categoriesTitleHtml = "snippets/categories-title-snippet.html";
2020
var categoryHtml = "snippets/category-snippet.html";
21-
var menuItemsUrl =
21+
var menuItemsUrl =
2222
"https://davids-restaurant.herokuapp.com/menu_items.json?category=";
2323
var menuItemsTitleHtml = "snippets/menu-items-title.html";
2424
var menuItemHtml = "snippets/menu-item.html";
@@ -36,8 +36,8 @@ var showLoading = function (selector) {
3636
insertHtml(selector, html);
3737
};
3838

39-
// Return substitute of '{{propName}}'
40-
// with propValue in given 'string'
39+
// Return substitute of '{{propName}}'
40+
// with propValue in given 'string'
4141
var insertProperty = function (string, propName, propValue) {
4242
var propToReplace = "{{" + propName + "}}";
4343
string = string
@@ -54,19 +54,19 @@ var switchMenuToActive = function () {
5454

5555
// Add 'active' to menu button if not already there
5656
classes = document.querySelector("#navMenuButton").className;
57-
if (classes.indexOf("active") == -1) {
57+
if (classes.indexOf("active") === -1) {
5858
classes += " active";
5959
document.querySelector("#navMenuButton").className = classes;
6060
}
6161
};
6262

6363
// On page load (before images or CSS)
6464
document.addEventListener("DOMContentLoaded", function (event) {
65-
66-
// TODO: STEP 0: Look over the code from
67-
// *** start ***
68-
// to
69-
// *** finish ***
65+
66+
// TODO: STEP 0: Look over the code from
67+
// *** start ***
68+
// to
69+
// *** finish ***
7070
// below.
7171
// We changed this code to retrieve all categories from the server instead of
7272
// simply requesting home HTML snippet. We now also have another function
@@ -75,14 +75,14 @@ document.addEventListener("DOMContentLoaded", function (event) {
7575
// random category into the home HTML snippet, and then insert that snippet into our
7676
// main page (index.html).
7777
//
78-
// TODO: STEP 1: Substitute [...] below with the *value* of the function buildAndShowHomeHTML,
78+
// TODO: STEP 1: Substitute [...] below with the *value* of the function buildAndShowHomeHTML,
7979
// so it can be called when server responds with the categories data.
8080

8181
// *** start ***
8282
// On first load, show home view
8383
showLoading("#main-content");
8484
$ajaxUtils.sendGetRequest(
85-
allCategoriesUrl,
85+
allCategoriesUrl,
8686
[...], // ***** <---- TODO: STEP 1: Substitute [...] ******
8787
true); // Explicitely setting the flag to get JSON from server processed into an object literal
8888
});
@@ -92,7 +92,7 @@ $ajaxUtils.sendGetRequest(
9292
// Builds HTML for the home page based on categories array
9393
// returned from the server.
9494
function buildAndShowHomeHTML (categories) {
95-
95+
9696
// Load home snippet page
9797
$ajaxUtils.sendGetRequest(
9898
homeHtmlUrl,
@@ -102,7 +102,7 @@ function buildAndShowHomeHTML (categories) {
102102
// Pay attention to what type of data that function returns vs what the chosenCategoryShortName
103103
// variable's name implies it expects.
104104
// var chosenCategoryShortName = ....
105-
105+
106106

107107
// TODO: STEP 3: Substitute {{randomCategoryShortName}} in the home html snippet with the
108108
// chosen category from STEP 2. Use existing insertProperty function for that purpose.
@@ -114,15 +114,15 @@ function buildAndShowHomeHTML (categories) {
114114
// $dc.loadMenuItems('L')
115115
// Hint: you need to surround the chosen category short name with something before inserting
116116
// it into the home html snippet.
117-
//
117+
//
118118
// var homeHtmlToInsertIntoMainPage = ....
119-
119+
120120

121121
// TODO: STEP 4: Insert the the produced HTML in STEP 3 into the main page
122122
// Use the existing insertHtml function for that purpose. Look through this code for an example
123-
// of how to do that.
123+
// of how to do that.
124124
// ....
125-
125+
126126
},
127127
false); // False here because we are getting just regular HTML from the server, so no need to process JSON.
128128
}
@@ -171,8 +171,8 @@ function buildAndShowCategoriesHTML (categories) {
171171
// Switch CSS class active to menu button
172172
switchMenuToActive();
173173

174-
var categoriesViewHtml =
175-
buildCategoriesViewHtml(categories,
174+
var categoriesViewHtml =
175+
buildCategoriesViewHtml(categories,
176176
categoriesTitleHtml,
177177
categoryHtml);
178178
insertHtml("#main-content", categoriesViewHtml);
@@ -185,10 +185,10 @@ function buildAndShowCategoriesHTML (categories) {
185185

186186
// Using categories data and snippets html
187187
// build categories view HTML to be inserted into page
188-
function buildCategoriesViewHtml(categories,
188+
function buildCategoriesViewHtml(categories,
189189
categoriesTitleHtml,
190190
categoryHtml) {
191-
191+
192192
var finalHtml = categoriesTitleHtml;
193193
finalHtml += "<section class='row'>";
194194

@@ -198,10 +198,10 @@ function buildCategoriesViewHtml(categories,
198198
var html = categoryHtml;
199199
var name = "" + categories[i].name;
200200
var short_name = categories[i].short_name;
201-
html =
201+
html =
202202
insertProperty(html, "name", name);
203-
html =
204-
insertProperty(html,
203+
html =
204+
insertProperty(html,
205205
"short_name",
206206
short_name);
207207
finalHtml += html;
@@ -226,9 +226,9 @@ function buildAndShowMenuItemsHTML (categoryMenuItems) {
226226
function (menuItemHtml) {
227227
// Switch CSS class active to menu button
228228
switchMenuToActive();
229-
230-
var menuItemsViewHtml =
231-
buildMenuItemsViewHtml(categoryMenuItems,
229+
230+
var menuItemsViewHtml =
231+
buildMenuItemsViewHtml(categoryMenuItems,
232232
menuItemsTitleHtml,
233233
menuItemHtml);
234234
insertHtml("#main-content", menuItemsViewHtml);
@@ -241,15 +241,15 @@ function buildAndShowMenuItemsHTML (categoryMenuItems) {
241241

242242
// Using category and menu items data and snippets html
243243
// build menu items view HTML to be inserted into page
244-
function buildMenuItemsViewHtml(categoryMenuItems,
244+
function buildMenuItemsViewHtml(categoryMenuItems,
245245
menuItemsTitleHtml,
246246
menuItemHtml) {
247-
248-
menuItemsTitleHtml =
247+
248+
menuItemsTitleHtml =
249249
insertProperty(menuItemsTitleHtml,
250250
"name",
251251
categoryMenuItems.category.name);
252-
menuItemsTitleHtml =
252+
menuItemsTitleHtml =
253253
insertProperty(menuItemsTitleHtml,
254254
"special_instructions",
255255
categoryMenuItems.category.special_instructions);
@@ -263,40 +263,40 @@ function buildMenuItemsViewHtml(categoryMenuItems,
263263
for (var i = 0; i < menuItems.length; i++) {
264264
// Insert menu item values
265265
var html = menuItemHtml;
266-
html =
266+
html =
267267
insertProperty(html, "short_name", menuItems[i].short_name);
268-
html =
269-
insertProperty(html,
268+
html =
269+
insertProperty(html,
270270
"catShortName",
271271
catShortName);
272272
html =
273273
insertItemPrice(html,
274274
"price_small",
275-
menuItems[i].price_small);
275+
menuItems[i].price_small);
276276
html =
277277
insertItemPortionName(html,
278278
"small_portion_name",
279279
menuItems[i].small_portion_name);
280-
html =
280+
html =
281281
insertItemPrice(html,
282282
"price_large",
283283
menuItems[i].price_large);
284284
html =
285285
insertItemPortionName(html,
286286
"large_portion_name",
287287
menuItems[i].large_portion_name);
288-
html =
289-
insertProperty(html,
288+
html =
289+
insertProperty(html,
290290
"name",
291291
menuItems[i].name);
292-
html =
293-
insertProperty(html,
292+
html =
293+
insertProperty(html,
294294
"description",
295295
menuItems[i].description);
296296

297297
// Add clearfix after every second menu item
298298
if (i % 2 !== 0) {
299-
html +=
299+
html +=
300300
"<div class='clearfix visible-lg-block visible-md-block'></div>";
301301
}
302302

@@ -341,4 +341,3 @@ function insertItemPortionName(html,
341341
global.$dc = dc;
342342

343343
})(window);
344-

0 commit comments

Comments
 (0)