Try using this code instead:
$('document').ready(function() {
$.each(questions, function(i, x) {
$('.input').eq(i).val(x.question);
$('.output').eq(i).attr("answer", x.answer);
$('.input').prop('readonly', true);
});
$(".output").on("keyup", function (){
checkAnswer(this);
});
});
function checkAnswer(e) {
let useranswer = $(e).val();
let realanswer = $(e).attr("answer");
if (realanswer == useranswer) {
$(e).css("background-color", "green");
} else {
$(e).css("background-color", "white");
}
}
This will add an attribute to the all the ""s with "output" class and then it will run the "checkAnswer" function "keyup" for those ""s to see if the answer is correct or not.