-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshowReviews.js
47 lines (38 loc) · 1.26 KB
/
showReviews.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*global $*/
var showReviews = (function() {
"use strict";
var pub = {};
var customerReviews;
var index;
/* This function shuffles through the reviews and displays them on the home page */
function displayReview() {
$("#reviews").empty();
$("#reviews").append("<h3>" + customerReviews[index].title + "</h3>");
$("#reviews").append("<p>" + customerReviews[index].author + "</p>");
$("#reviews").append('<blockquote>"' + customerReviews[index].reviewcontent + '"</blockquote>');
index++;
if (index === customerReviews.length) {
index = 0;
}
}
/* Setup function reads the data from reviews.json */
pub.setup = function() {
$.ajax ({
type: "GET",
url: "./Resources/reviews.json",
dataType: 'json',
cache: false,
success: function(data) {
customerReviews = data;
index = 0;
displayReview();
setInterval(displayReview, 7000);
},
error: function() {
$("#reviews").html("Sorry, something has gone wrong on our end.");
}
});
}
return pub;
}());
$(document).ready(showReviews.setup);