Need help with a Javascript project - It doesn't work!

<%= @topic_view.topic.title %>
<%= @topic_view.topic.average_rating %> <%= @topic_view.topic.posts.count { |p| !!p.custom_fields['rating'] } %>

I have built a tip calculator on Codepen. It looks like I did everything right, but it doesn’t work! I even checked it against other tip calculators on Codepen. I have reviewed the Javascript and HTML a million times and I need a fresh set of eyes. Would you please take a look and give me an idea where the bug is? Here is the link: https://codepen.io/pjmofperk/pen/RzzQPQ

Thank you!

@pjmofperk
You have to type lowercase ‘g’ instead of uppercase ‘G’ in getElementById.

  let billAmt = document.GetElementById("billInput").value;
  let servQual = document.GetElementbyId("qualitySelector").value;
  let numPeople = document.GetElementById("totalPeople").value;
1 Like

I found some typos and misconceptions in your code. I fixed it and commented here: https://codepen.io/michelmarechal/pen/ZgzZWa?editors=0010

You have a lot typos with document.getElementById. Some cases the ‘g’ is capitalized some cases the ‘b’ isn’t capitalized.

Also, servQual = 0 should be servQual == 0 since you are comparing their values, not assigning it.

By the way, something you can do to figure out what to fix is to bring up the console, it’ll tell you what errors are happening so you can fix your code.

Thank you all very much for your help!

Patrick