Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can I make a string "['A', 'B', 'C']" into a list? JavaScript

So I made a Freckle by Renissance hack in JavaScript and I retrived the JSON base64 and decoded it using the atob() function where you get the answer but I’m just wondering if I can make the decoded string: "[‘A’, ‘B’, ‘C’]" (The correct answers) into a list excluding the ‘[]’ and ‘,’.

async function getAnswer(){
    var id = document.getElementsByClassName("math-question__wrapper___iRtlD")[0]["dataset"]["questionId"];
    var response = await fetch("https://api.freckle.com/2/math/questions/"+id+"?lang=en", {
      method: "GET",
    
      headers: {
        "Content-type": "application/json; charset=UTF-8"
      }
    });

    
    json = await response.json();
    var answer=json["obfuscated-correct-answers"];
    if (typeof answer == "undefined") {
        answer=json['obfuscated-fill-in-the-blanks-correct-answers'];
    }

    
    var final=atob(answer);
    console.log(final);
}
getAnswer();

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The base 64 string decodes to valid JSON, so use JSON.parse() after calling atob().

async function getAnswer() {
  var id = document.getElementsByClassName("math-question__wrapper___iRtlD")[0]["dataset"]["questionId"];
  var response = await fetch("https://api.freckle.com/2/math/questions/" + id + "?lang=en", {
    method: "GET",

    headers: {
      "Content-type": "application/json; charset=UTF-8"
    }
  });


  json = await response.json();
  var answer = json["obfuscated-correct-answers"];
  if (typeof answer == "undefined") {
    answer = json['obfuscated-fill-in-the-blanks-correct-answers'];
  }

  var final = JSON.parse(atob(answer));
  console.log(final);
}
getAnswer();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading