Cod: Selectaţi tot
function buildCom(id) {
$.getJSON("json/comment.json", function(data) {
var comId = $("#" + id);
var rnd = Math.floor(Math.random() * (data.comment.length - 1))
var index = Math.Max(0, rnd - 4)
$.each($(data.comment).slice(index, index + 4)), function(i, elem) {
var $this = $(
'<div class="col-xs-12 col-sm-6 col-md-3 col-lg-3 faq">' +
'<div class="panel">' +
'<div class="panel-heading text-center">' +
'<img src="' + elem.imgPath + '" alt=""/>' +
'</div>' +
'<div class="panel-body text-center">' +
'<p class="name">' + elem.name + '</p>' +
'<p class="age">' + elem.age + '</p>' +
'<p class="faq">' + elem.comment + '</p>' +
'</div>' +
'</div>' +
'</div>'
);
comId.append($this);
}
});
}
new buildCom("coment");
Cod: Selectaţi tot
Uncaught TypeError: Math.Max is not a function