Question: JavaScript - I need to get my js file to fire when the button is clicked. I am not sure what I am doing wrong.
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">
Change Calculator
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;
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
