Q:

Javascript. How to return the questions and correct answers to a Math.random

I'm fairly new to javascript and am having an issue. I found this code snippet and am trying to display the question, user answer, and correct answer from ask() after the user inputs their answers from all the questions. I've tried a for loop to display each index, but that simply returns true or false. 
Here's the code: 
<script>
    function ask() {
        var a = Math.floor(Math.random() * 10) + 1;
        var b = Math.floor(Math.random() * 10) + 1;
        var op = ["*", "+", "/", "-"][Math.floor(Math.random()*4)];
        return prompt("How much is " + a + " " + op + " " + b + "?") == eval( a + op + b);
    }

    var questions = [ask(), ask(), ask(), ask(), ask()],
        total = questions.length,
        correct = questions.filter(Boolean).length;

    alert( "You got "+correct+"/"+total+" correctly");
</script>

And you can test the current code here

A:

You can use an object to return from the ask() function.
JSFIDDLE DEMO
function ask() {
    var a = Math.floor(Math.random() * 10) + 1;
    var b = Math.floor(Math.random() * 10) + 1;
    var op = ["*", "+", "/", "-"][Math.floor(Math.random()*4)];

    return {
            question : "How much is " + a + " " + op + " " + b + "?",
            ansGiven: prompt("How much is " + a + " " + op + " " + b + "?"),
            ansCorrect : eval( a + op + b),
            get isCorrect(){return this.ansGiven == this.ansCorrect}
           };
}

var questions = [ask(), ask(), ask(), ask(), ask()],
    total = questions.length,
    correct = questions.filter(function(ans){return ans.isCorrect}).length;

alert( "You got "+correct+"/"+total+" correctly");
questions.forEach(function(q, i){
    alert("Question " +(i+1)+ " : " + q.question 
    + "\nAnswer: " + q.ansGiven 
    + "\nCorrect Answer: " + q.ansCorrect 
    + "\n You were " + ((q.isCorrect)?"Correct!":"Wrong!"));
});

