JSFiddle - React, Tailwind, and code Playground
HTML
<div ng-app="app" ng-controller="MyController"></div>
JavaScript
var app = angular.module('app', [])
app.controller('MyController', function ($scope) {
$scope.answers = ["a","c","b"];
$scope.correctAnswers = ["b", "a" , "d"];
$scope.compareArrays = function (arr1, arr2) {
var inBoth = [];
angular.forEach(arr1, function (a1) {
angular.forEach(arr2, function (a2) {
if (a1 == a2) {
inBoth.push(a1);
}
});
});
//return inBoth;
var correct = 'You got ' + inBoth.length + '/' + arr2.length + ' answers!';
var percentage = 'Correct: ' + ((inBoth.length / arr2.length) * 100).toFixed(2) + '%';
alert(correct + '\n' + percentage);
};
$scope.compareArrays($scope.answers, $scope.correctAnswers);
});