Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,158,275 members, 7,836,234 topics. Date: Tuesday, 21 May 2024 at 11:59 PM

Please Explain This Code To Me - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Please Explain This Code To Me (926 Views)

I Am Bored, I Just Tried This Code / Someone Please Explain Backend To Me / Please,Help Explain This Code In C (2) (3) (4)

(1) (Reply)

Please Explain This Code To Me by BabyApple(m): 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)

Ardamax Keylogger / Free Hosting & Domain / Help Me With The Solution To This Problem In C++

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 32
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.