Please Explain This Code To Me - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Please Explain This Code To Me (1013 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" .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 |
I Am Bored, I Just Tried This Code • Someone Please Explain Backend To Me • Please,Help Explain This Code In C • 2 • 3 • 4
Professional Ict Training Scholarship For Nigerians • Xml Validation Problem!. • Blogger
.innerHTML = survey.every(isSameAnswer);