jeudi 17 septembre 2020

Im making a personality quiz and need to convert answer codes to a word

I'm trying to make a personality quiz and I want to convert the answer code I got (yes is an A and no is a B) its a simple 4 question personality quiz for kids. I have a function that puts all 4 questions "identifiers" (the A and B) into a string then I want to make an if statement that tells the program to output an answer based on that 4 letter code. So basically when it is AAAA the program needs to convert that to a Leopard(AAAA = Leopard) I have the code that outputs it to the HTML file I just need to convert that AAAA to a word.

function getEndingSentence() {
    var quizRadio = document.getElementsByName("rq");
    var answerCode = ''; //It's easier to handle if we simply merge all sentences into a string
    for (var i = 0; i < quizRadio.length; i++) {
        if (quizRadio[i].checked) {
            answerCode += quizRadio[i].getAttribute("data-endingsentence"); //these are the attributes used to generate quiz answers
        }
    }
    return answerCode;
}

function getAnswer() {
    var finalAnswer = ''
    var preAnswer = getEndingSentence();
    if (preAnswer = "AAAA") {
    finalAnswer = 'Jagluiperd'
    } else {
        finalAnswer = 'Undefined'// just to test if the if statment works
    }
    return finalAnswer;
}

function setEndingSentence() {
    var personalityResults = getAnswer();
    document.getElementById("results_screen").className = "";
    document.getElementById("generated_text").innerHTML = personalityResults; 

} 

Aucun commentaire:

Enregistrer un commentaire