I am stuck on this challenge help me
I have attached event handler to the noOfPeople input and in the event handler I call another function which is called validate field which calls validator on each input and from the validators whcih the validateField calls in the validatorSelectTip function the this keyword refers to undefined. why is that because I have attached the bind keyword when I call the event handler on the "noOfPeople" input.
this is the live-site url: https://aemrobe.github.io/Tip-calculator-app-main/
this is the git repo: https://github.com/aemrobe/Tip-calculator-app-main.git
GitHub
GitHub - aemrobe/Tip-calculator-app-main
Contribute to aemrobe/Tip-calculator-app-main development by creating an account on GitHub.
11 Replies
you are trying to add event listeneds to strings
remove the .value from the end
it won fix everything, but that is the first huge blinder
which one is string noOfPeople isnot a string
yes it is
GitHub
Tip-calculator-app-main/script.js at f8d96c95b23f2467945dc3e23de9e9...
Contribute to aemrobe/Tip-calculator-app-main development by creating an account on GitHub.
.value means "the value in the element" which is a string
I stopped doing them. I have changed it and it is working. the error was I should use the call keyword when I call the valildators in the validateField function.
🤔
you can see my solution here: https://aemrobe.github.io/Tip-calculator-app-main/
i will later
not gonna lie, your solution is exactly the type of thing you should never do
but, it's just for a challenge, and the code sorta kinda almost works, which is fine
I have learned oob and I put it to practice then. What is the best practice for it. Would you suggest me.
well, the big bad one is that you are using global variables to a class that has a constructor
and then, you are re-implementing things that are already implemented into html and javascript, but you cant use them because you didnt use the right attributes and elements
you have a button that has javascript that manually clears the inputs, instead of using a form with a <button type="reset"> to do everything for you
you can even listen to the reser event in the form