0
What I forgot, please help me My Javascript code isn't working ??
5 odpowiedzi
+ 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 );
}
}
+ 2
Thank you you did it.
+ 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
+ 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.
+ 1
Okay 👍