<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The every() Method</h2>
<p>Check if every answers in the array is the same:</p>
<p id="demo"></p>
<script>
const survey = [
{ name: "Steve", answer: "Yes"},
{ name: "Jessica", answer: "Yes"},
{ name: "Peter", answer: "Yes"},
{ name: "Elaine", answer: "No"}
];
function isSameAnswer(el, index, arr) {
if (index === 0){
return true;
}
else {
return (el.answer === arr[index - 1].answer);
}
}
document.getElementById("demo").innerHTML = survey.every(isSameAnswer);
</script>
</body>
</html>