₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,079 members, 8,420,191 topics. Date: Thursday, 04 June 2026 at 01:15 PM

Toggle theme

Please Explain This Code To Me - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingPlease Explain This Code To Me (1014 Views)

1 Reply

Please Explain This Code To Me by BabyApple(op): 2:50pm On Dec 05, 2018
<!DOCTYPE html>
<html>
<body>

<p>Click the button to check if all the answer values in the array is the same.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
var survey = [
{ name: "Steve", answer: "Yes"},
{ name: "Jessica", answer: "Yes"},
{ name: "Peter", answer: "Yes"},
{ name: "Elaine", answer: "No"}
];

function isSameAnswer(el,index,arr) {
// Do not test the first array element, as you have nothing to compare to
if (index === 0){
return true;
}
else {
//do each array element value match the value of the previous array element
return (el.answer === arr[index - 1].answer);
}
}

function myFunction() {
document.getElementById("demo"wink.innerHTML = survey.every(isSameAnswer);
}
</script>

</body>
</html>
Re: Please Explain This Code To Me by tactics: 4:11pm On Dec 05, 2018
It is just to test if the answer values in the survey arrays are same or not
Re: Please Explain This Code To Me by Hibrahym: 7:08pm On Dec 05, 2018
How to Ask Question The Smart Way: http://www.catb.org/esr/faqs/smart-questions.html
1 Reply

I Am Bored, I Just Tried This CodeSomeone Please Explain Backend To MePlease,Help Explain This Code In C234

Api Integration Work To DoNevermind, wrong trend.What Exactly Do Modifier Types In C++ Do? More Emphasis On Integer Modifiers