Can someone please tell me what's wrong with this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can someone please tell me what's wrong with this code?

https://code.sololearn.com/W5j86X2yt5QG/?ref=app

15th Oct 2019, 9:34 AM
sujay simha
sujay simha - avatar
6 Answers
+ 2
sujay simha Try this, I'm not good in web programming, but probably this gives you an idea. Feel free to ask if there's a doubt. I'll try to clear up best I can. <!DOCTYPE html> <html> <head> <title>Search array</title> </head> <body> <form> <label>Name: <input type="text" id="username"></label> <button type="button" onclick="search()">search</button><br /> </form> <script> var persons; window.onload = function() { persons = [{name:"saritha", age:39}, {name:"sujay", age:10}, {name:"kalyan", age:20}, {name:"madhu", age:43}]; }; function search() { var ask = document.getElementById("username").value.toLowerCase(); if(ask.length == 0) return false; persons.forEach(function(person) { if(person.name == ask) console.log(person.name + " " + person.age + " years"); }); } </script> </body> </html>
15th Oct 2019, 2:31 PM
Ipang
+ 4
No problem buddy, I am glad if it helps. And don't worry, I didn't write the whole code, I copied parts of yours : )
15th Oct 2019, 4:59 PM
Ipang
+ 3
Can you elaborate more on what you expected from the code please? I'm not getting any idea. P.S. Please add HTML to Relevant Tags section to add scope clarity 👍 (Edit) Tags had been updated. Thanks for understanding 👍
15th Oct 2019, 11:09 AM
Ipang
+ 2
Ipang, well, I need to write a code which will print a search bar and when I click the search button, if the word is in the Array, I should print that btw, I did that
15th Oct 2019, 11:11 AM
sujay simha
sujay simha - avatar
+ 2
thanks a lot Ipang btw, I'm really sorry for making you type all the code
15th Oct 2019, 4:51 PM
sujay simha
sujay simha - avatar
+ 2
😁😁
15th Oct 2019, 5:24 PM
sujay simha
sujay simha - avatar