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

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!