jeudi 19 août 2021

change API data depending on if statment

could anyone help me, I'm trying to fetch data through API , and the URL contains two object and I targeted the quizzes , "quizzes": [2 items], "warnings": [] quizzes return me two objects with their details, what I'm trying to achieve is to add if statement to retrieve the grades (another API) depends on quiz name and it is working well , but I want to add inside it another if to retrieve grades depends on the another quiz name, please see the code below how to target posttest inside pretest they have the same key and I want the data to be changed depends on quiz name.

var get_quiz = {
  "url": "MyURL"
};

  $.ajax(get_quiz).done(function (get_quiz_res) {
  var reslength = Object.keys(get_quiz_res).length;
  for (let b = 0; b < reslength; b++) {
    
    var get_grade = {
   "url": "*******&quizid="+get_quiz_res.quizzes[b].id"
   };


$.ajax(get_grade).done(function (get_grade_res) {

 var posttest=''
if (get_quiz_res.quizzes[b].name === "Post Test"){
  posttest =  get_grade_res.grade;
}

    if (get_quiz_res.quizzes[b].name === "Pre Test"){
            var row = $('<tr><td>' + userincourseres[i].fullname + '</td><td>' + get_grade_res.grade + '</td><td>' + posttest + '</td><td>');
            $('#myTable').append(row);
    }

  });

  }
});

the userincourseres[i].fullname from another api and it is working.

thank you kindly

Aucun commentaire:

Enregistrer un commentaire