Change Calculator
JavaScript - I need to get my js file to fire when the button is clicked. I am not sure what I am doing wrong.
Here is my html file:
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Here is my calculate_coins.js file:
var $ = function (id) {
return document.getElementById(id);
}
var calCents = function(){
var cents = $("myCents").value;
if(cents > 24) {
var quarters = Math.floor(cents/25);
//cents = cents%.25;
$("quarters").value = quaters
}
if(cents > 9) {
var dimes = Math.floor(cents/10);
//cents = cents%.10;
$("dimes").value = dimes;
}
if(cents > 4) {
var nickels = Math.floor(cents/5);
//cents = cents%.05;
$("nickels").value = nickles;
}
if(cents > 0) {
var pennies = Math.floor(cents/1);
$("pennies").value = pennies;
}
}
There are 3 Steps involved in it
See step-by-step solutions with expert insights and AI powered tools for academic success
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started