Jump to content

.value (its able to get and value and add a value)


david1972

Recommended Posts

//Assignment 3
"use strict";
const $ = selector => document.querySelector(selector);
const processEntry = () => {
    const income = parseFloat($('#income').value);

    if (isNaN(income) || income <= 0){
        alert("Income error.");                   //correct alert. original bug.
        focusAndSelect("#income");
    }
    else {
        calculatetax(income)
        console.log("firt if / else loop made else for >0");
    }
};
document.addEventListener("DOMContentLoaded", () => {
    // add event handlers
    $("#calculate").addEventListener("click", processEntry);
});
const calculatetax = (income) => {
    if(income <= 9875){
        income = (income*0.10).toFixed(2);
    }else if(income >=9876 && income <=40125) {
        income = ((income - 9875)*0.12 + 987.50).toFixed(2);
    }else if(income >=40126 && income <=85525){
        income = ((income - 40125)*0.22 + 4617.50).toFixed(2);
    }else if(income >=85526 && income <=163300){
        income = ((income - 85525)*0.24 + 14605.50).toFixed(2);
    }else if(income >=163301 && income <=207350){
        income = ((income - 163300)*0.32 + 33271.50).toFixed(2);
    }else if(income >=207350 && income <=518400){
        income = ((income - 207350)*0.35 + 47367.50).toFixed(2);
    }else if(income >518401 && income <=10000000){
        income = ((income - 518400)*0.37 + 156235.00).toFixed(2);
    };
    $("#tax").value = income
}

Edited by david1972
removed IDE format color
Link to comment
Share on other sites

const $ = selector => document.querySelector(selector);
const processEntry = () => {
    let userEntry = parseInt($("#cents").value);
    if (userEntry <0 || userEntry >99){
        alert("only 0-99 please");
    } else {
        makeChange(userEntry);
        $("#cents").focus();
    }
}
const makeChange = (userEntry) => {               //CHANGE
    let c = 0                                     //left over
    let p = userEntry
    let quarters =  p / 25;
    c = p  % 25
    $("#quarters").value = Math.floor(quarters);    // calculations on left over with floor function.

    let dimes =  c / 10;
    c = c  % 10
    $("#dimes").value = Math.floor(dimes);

    let nickels =  c / 5;
    c = c  % 5
    $("#nickels").value = Math.floor(nickels);
                
    let pennies =  c / 1;
    c = c  % 1
    $("#pennies").value = Math.floor(pennies);

}
document.addEventListener("DOMContentLoaded", () => {
    $("#calculate").addEventListener("click", processEntry);
    //$("#userEntry").focus();

});

Link to comment
Share on other sites


"use strict";

const scores = [];

// const $ = function(selector) {                         //from $90 to arrow function below
//     return document.querySelector(selector);

const $ = selector => document.querySelector(selector);

//const addScore = function(selector) {                  // function expression to change.
const addScore =()=> {                                  // function now arrow function.
const score = parseInt($("#score").value);
    if (score >= 0 && score <= 100) {
        scores[scores.length] = score;
        $("#score").value = "";
        $("#average").value = calculateAverage();
    }
    else {
        alert("Score must be a valid number from 0 through 100");
    }
    $("#score").focus();
};

const calculateAverage = () => {                     // now Arrow function
    let total = 0;
    for (let val of scores) {
        total = total + val;
    }
    return parseInt(total / scores.length);
};

// const processDOM =()=> {                            // changed: removed function
//     $("#add").addEventListener("click", addScore);
//     $("#score").focus();
// }

document.addEventListener("DOMContentLoaded", ()=> {                            // changed: removed function
    $("#add").addEventListener("click", addScore);
    $("#score").focus();
}
);
 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...