Hey Bard, write a responsive Javascript Search Engine app for me..

Riccardo Carlesso
6 min readNov 20, 2023

--

I suck at Javascript. šŸ˜’ Itā€™s time to admit it. šŸ˜… Letā€™s see how Bard helped me overcome this limitationā€¦ and create this app!

I tried for years to cope and survive in a world which seems to be unable to exist without Javascript, and last weekend I succumbed. Time to ask your favorite JS developer Chris to point you at some good documentation and start reading about this weird language.

Promises, promisesā€¦ unless? Wait, what if an LLM could code the app for me? Maybe Iā€™m not good to start the project myself, but what if Bard can do it for me, I should be able to tweak the code myself.

TL;DR If you donā€™t want to read my Italian drama, jump to the code (or see the result on Cloud Run).

Two days ago, I was babysitting my kids; playing with my mobile phone while they were playing with Legoā€¦

Little Seby in the Lego room in Google Zurich

.. and I started asking Bard a question. But wait, ā€œhow do I make sure the question remains available when I go back home to my big computer?ā€ I was quite surprised by the answer.

The Coding concept

Whatā€™s my idea? Say you have a gazillion articles / assets and want to be fast at searching on them. But you canā€™t accept a 1ā€“2 seconds latency from a typical server-side website search.

Flash is searching through all my docs ina static, local JSON! Barry likes to win easy :)

I want a search bar where I can start typing stuff and the choice starts to diminish. Then I want to have a number of cards with the results (from a static JSON ā€” Iā€™ll make it dynamic in a next episode!). I also want to have some rudimental clicking to narrow down the choice, say with a Boolean ā€œis this a technical article).

A quick and customizable search bar.

Write a good prompt

My kids are delving into plenty of Legos, so I have plenty of time to try a verbose and well planned prompt. After all, I want it to write an app for me! Letā€™s not save time and details.

Prompt 1: ā€œI would like to build a small and responsive search engine. The DB Is small and static so I donā€™t need anything complicated. I just want to have a frontend JavaScript where you start typing a word and it searches for all the elements matching this word in title or description. The only important thing to me is responsiveness so every time you type a letter it starts selecting just things matching it, so you want to write say ā€œpistachioā€, the selection should start kicking in already with ā€˜pā€™, ā€˜piā€™, ā€˜pisā€™, and so on. Can you help me write the code?ā€

Iā€™m so ignorant on JS that Iā€™m not even sure this is something you can do fully on client-side ( index.html+ script.js) or if you need some server-side effort (add node.jsto the mix) to provide the JSON (although on the server-side I have 20-year expertise ā€” this part I can do without help).

Bard reply might surprise you..

Bard answer

Now, Bard started with a confident ā€œSure, hereā€™s the JavaScript code for a small and responsive search engine that works with a static database:ā€ but I donā€™t trust what I see. Plus, I donā€™t have a computer with me, so I canā€™t try the code. I asked him to do two things that Google is really good at doing:

  • export in email (cheap / persistent)
  • export to GDoc (richer / can edit)

Look:

Bard exports to GDocs and GMail in case you want to elaborate on your brainstorming idea.

When I was home I had plenty to choose from: my šŸ“¬ GMail inbox, my šŸ“ƒ Google Docs link. what I didnā€™t know is that the conversation is saved conveniently in a top left tab, and you can pin it ā€” until youā€™re done with your project.

I paste the JS / HTML code andā€¦ it works FROM SCRATCH! Teh first tentative works! Wow Iā€™m impressed. I start putting the code into github for posterity and for making potentially breaking changes.

Letā€™s add complexity. Add a Boolean and multi-parameter search!

Prompt2. ā€œWow! Say I want to do something a bit more complex for example selecting a Boolean (isTechnical=true/false) which is in the frontend as checkbox and in the JSON, and I want to sort the result by some kind of rating? Can you help me add those two functionalities both to html and to JavaScript?ā€

Result:

The result is impeccable ā€” except with the Pasta Primavera which definitely not šŸ‡®šŸ‡¹-compliant!

Note that Bard gives me the index.html code, the script.jscode , and also a pre-baked JSON which responds to my requirements (a isTechnical boolean and a float rating).

Add little nits: CSS and Cards

Prompt 3. Wow this is amazing! Final thing, can you share a little css snippet to make this look nice and professional? Iā€™m bad at CSS.

This made the final visualization a bit better (not much).

Prompt 4. Fantastic! Last thing. I would like to visualize the search result as nicely formatted cards, think of three rectangles per row, with title description and maybe a small image turned into a square with rounded corners. Can you help me with html and CSS?

And this is the first time Bard makes a mistake. He gives me a HTML code which seems like Angular (ngFor ):

This is a mistake: `ngFor` only exists in Angular framework (I presume?)

Result

The app is currently served by cloud run here: https://js-simple-search-bsl7ylv4hq-ew.a.run.app/

This is the final result in GIF format:

The functionalities it demonstrates are:

  • responsive sub-JSON search function (every letter triggers a search on Title or Description)
  • boolean selection (isTechnical or not)
  • Sort by rating (number) or by Title (string)

Conclusions

As a person who canā€™t even code a strlen() in Javascript, I was able to create a simple / dumb ā€” yet customized ā€” website within an hour on a Saturday afternoon (when my wife was babysitting).

bard.google.com gave me good code from the beginning, and responded correctly to the next 2 questions. The first error was at the 4th prompt (!). Also, on the negatives, the CSS for cards was pretty ugly so I had to fix it myself (luckily I speak some rudimental Boostrap).

I found Bard can be a pretty good companion if you have time to kill away from keyboard, and you want to go with the flow in some brainstorming phase, ready to copy the content when youā€™re back to your workstation.

--

--

Riccardo Carlesso

Father, pianist, Rubyist, Googler, linguist, ironman. Calls Zurich / Dublin / Bologna his home.