david1972
-
Posts
5 -
Joined
-
Last visited
Content Type
Profiles
Forums
Events
Posts posted by david1972
-
-
JS is slowly sinking in. If you can handle event listeners, the DOM, get and set values, then you can do most things?
querySelector
const $ = selector => document.querySelector(selector);using querySelector's
const score = parseInt($("#score").value);arrow function example
const addScore =()=> { code lines };.value function get input
const variableName = parseInt($("#id").value);
.value function set input
$("#id").value = "";DOMContentLoaded
document.addEventListener("DOMContentLoaded", ()=> {function calls} );addEventListener to button
$("#id").addEventListener("click", functionName); -
"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();
}
);
-
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();});
-
//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
}
I don't understand this correlated subquery
in SQL
Posted
My question: Why does the inner query need a table alias?
Q: Use a correlated subquery to return one row per vendor
representing the vendor's largest invoice.
Each row should include vendor_id, vendor_name, invoice_total,
and invoice_date. Order by invoice_totol in DESC.
______________________________________________________________________
SELECT v.vendor_id, vendor_name, invoice_total, invoice_date
FROM vendors v JOIN invoices i ON v.vendor_id = i.vendor_id
WHERE invoice_total = (
SELECT MAX(invoice_total) FROM invoices
WHERE vendor_id = v.vendor_id
)
ORDER BY invoice_total DESC; -- 41 vs he got 36.