What I forgot, please help me My Javascript code isn't working ?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What I forgot, please help me My Javascript code isn't working ??

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

24th Mar 2023, 8:39 AM
Jashwan Mathur
Jashwan Mathur - avatar
5 Answers
+ 5
function calc(adults ,children ){ return price = adults *12 + children *6; } window.onload = function (){ let btn = document.getElementById("buybtn"); btn.onclick = function () { let adults = document.getElementById("adult").value; let children = document.getElementById("children").value; let prce = calc(adults ,children ); alert (prce ); } }
24th Mar 2023, 9:24 AM
JME
+ 2
Thank you you did it.
24th Mar 2023, 9:29 AM
Jashwan Mathur
Jashwan Mathur - avatar
+ 2
function calc(adults,children){ return adults*12 + children*6 } Or: const calc = (adults,children)=>{ return adults*12 + children*6 } Or: const calc = (adults,children)=> adults*12 + children*6
24th Mar 2023, 12:21 PM
Solo
Solo - avatar
+ 2
You put a space after "window" and typed "window .onload" , instead of "window.onload". These kinds of problems are normal when you begin to code; however, I would encourage you to try reading your code thoroughly and find the problem, learn how to debug. That's how programmers become good at finding where the error is. One more thing if your JS code doesn't work on mobile phone app, which it doesn't most of the time, put the JS code in HTML file using <script> tag.
25th Mar 2023, 9:17 AM
Harman Maan
Harman Maan - avatar
+ 1
Okay 👍
28th Mar 2023, 2:42 AM
Jashwan Mathur
Jashwan Mathur - avatar