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 :
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();