Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,162,112 members, 7,849,470 topics. Date: Monday, 03 June 2024 at 10:09 PM |
Nairaland Forum / Science/Technology / Programming / Please Explain This Code To Me (928 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".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)
We Will Be Glad To Manage Your Tech Issues & Web Design - Emwanta AIRHUNMWUNDE / E Laptop Table For BULK Sale!!(Off for now) / Application close 30th may, 2020: Junior Website Designer Needed Urgently
(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. 7 |