Skip to content

Commit

Permalink
calculator changes commit
Browse files Browse the repository at this point in the history
  • Loading branch information
arolus committed Nov 14, 2023
1 parent ed7ddcb commit 054fe6b
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 18 deletions.
Binary file modified assets/images/screenshot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/screenshot-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions assets/js/all-calculators.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ var allCalculators = [
"uri": "/hours-calculator/",
"image": "../images/icon-96.png"
},
{
"title": "Grade Calculator",
"description": "Our weighted grade calculator shows your average and what to earn for the final grade you want. A timesaver if you don't know how to calculate grades!",
"uri": "/grade-calculator/",
"image": "../images/icon-96.png"
},
{
"title": "Basic Calculator",
"description": "This online calculator performs basic mathematical operations like addition, subtraction, division, and multiplication. You can use the calculator to find percentages and taxes.",
Expand Down Expand Up @@ -239,6 +245,12 @@ var allCalculators = [
"uri": "/compound-interest-calculator/",
"image": "../images/icon-96.png"
},
{
"title": "Slope Calculator",
"description": "The slope calculator finds the slope of a line using the slope formula. It can also find point coordinates, incline angle, and length if the slope and one point are known.",
"uri": "/slope-calculator/",
"image": "../images/icon-96.png"
},
{
"title": "Variance Calculator",
"description": "Given a discrete data set representing a sample or a population, the calculator calculates the mean, variance, and standard deviation and displays the workflow involved in the calculation.",
Expand Down Expand Up @@ -425,6 +437,12 @@ var allCalculators = [
"uri": "/mean-median-mode-range-calculator/",
"image": "../images/icon-96.png"
},
{
"title": "Z-Score Calculator",
"description": "The Z-Score Calculator helps to get the z-score of a normal distribution, convert between z-score and probability, and get the probability between 2 z-scores.",
"uri": "/z-score-calculator/",
"image": "../images/icon-96.png"
},
{
"title": "Permutation Calculator",
"description": "Permutations calculator will help determine the number of ways to obtain an ordered subset of r elements from a set of n elements.",
Expand All @@ -443,12 +461,24 @@ var allCalculators = [
"uri": "/body-type-calculator/",
"image": "../images/icon-96.png"
},
{
"title": "Probability Calculator",
"description": "The probability calculator can find two events' probability and the normal distribution probability. Learn more about probability's laws and calculations.",
"uri": "/probability-calculator/",
"image": "../images/icon-96.png"
},
{
"title": "Quartile Calculator",
"description": "The quartile calculator helps to find the first(Q1), second(Q2), and third(Q3) quartiles, interquartile range, minimum and maximum values, and range of a data set.",
"uri": "/quartile-calculator/",
"image": "../images/icon-96.png"
},
{
"title": "Right Triangle Calculator",
"description": "Right triangle calculator finds missing triangle measurements. It calculates side lengths, angles, perimeter, area, altitude-to-hypotenuse, inradius, and circumradius.",
"uri": "/right-triangle-calculator/",
"image": "../images/icon-96.png"
},
{
"title": "Tip Calculator",
"description": "Free tip calculator that helps people know how much to tip when receiving services from various businesses and workers. This tool also calculates how to split a bill and tip between a group of people.",
Expand Down Expand Up @@ -485,6 +515,12 @@ var allCalculators = [
"uri": "/work-hours-calculator/",
"image": "../images/icon-96.png"
},
{
"title": "Sample Size Calculator",
"description": "This sample size calculator enables you to calculate the minimum sample size and the margin of error. Learn about sample size, the margin of error, & confidence interval.",
"uri": "/sample-size-calculator/",
"image": "../images/icon-96.png"
},
{
"title": "Fraction to percent calculator",
"description": "Fraction to percent calculator converts proper and improper fractions to percentages. Calculator is using fraction-decimal-percent algorithm.",
Expand Down
24 changes: 19 additions & 5 deletions assets/js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,23 @@ window.output = {

// check erroneous result of expression (or if it's not string - check itself)
// usefull in cases when erroneous values of input fields are unknown
window.calc = (expression,scope) => {
window.calc = (expression,scope,resultType) => {
let result = expression;
scope = scope || {};
if(typeof expression == 'string'){
result = math.evaluate(expression,scope||{}); // can throw error as well
result = math.evaluate(expression,scope); // can throw error as well
}
if(isNaN(result)||result.im) {
throw new Error(`result is ${result}.`);
let valid = true;
switch(resultType){
case 'positive': valid = result > 0;
}
if(isNaN(result)||result.im||!valid) {
const args = Object.keys(scope).map(arg=>arg+'='+scope[arg]);
throw new Error(
`result of expression ${expression} is ${result}.`
+ (resultType ? `<br/>Should be ${resultType}.`:'')
+ (args.length != 0 ? `<br/>Args: ${args.join(', ')}.`:'')
);
}
return result;
};
Expand Down Expand Up @@ -160,7 +170,11 @@ window.input = {
error = message.toString();
}
// default message
message = `Value${Array.isArray(inputId)?'s':` "${this.get(inputId).value}"`} of "${inputId}" ${Array.isArray(inputId)?'are':'is'} invalid.<br/>${error}`;
if(Array.isArray(inputId) && inputId.length == 0){
message = `${error}`;
} else {
message = `Value${Array.isArray(inputId)?'s':` "${this.get(inputId).value}"`} of "${inputId}" ${Array.isArray(inputId)?'are':'is'} invalid.<br/>${error}`;
}
}
return this.error(inputId, message, true);
},
Expand Down
26 changes: 13 additions & 13 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<p class="input__title">Loan Amount</p>
<div class="input-field row">
<span class="input-field__hint">$</span>
<input type="text" class="input-field__input" placeholder="0" id="loan_amount" value="100000" />
<input type="text" class="input-field__input" placeholder="" id="loan_amount" value="100000" />

</div>
<div class="input-hints row">
Expand All @@ -50,7 +50,7 @@
<p class="input__title">Interest Rate</p>
<div class="input-field row">

<input type="text" class="input-field__input" placeholder="0" id="interest_rate" value="5" />
<input type="text" class="input-field__input" placeholder="" id="interest_rate" value="5" />
<span class="input-field__hint">%</span>
</div>
<div class="input-hints row">
Expand All @@ -66,7 +66,7 @@
<p class="input__title">Loan Term</p>
<div class="input-field row">

<input type="text" class="input-field__input" placeholder="0" id="loan_term_year" value="10" />
<input type="text" class="input-field__input" placeholder="" id="loan_term_year" value="10" />
<span class="input-field__hint">years</span>
</div>
<div class="input-hints row">
Expand All @@ -86,7 +86,7 @@

<div class="input-field row">

<input type="text" class="input-field__input" placeholder="0" id="loan_term_month" value="" />
<input type="text" class="input-field__input" placeholder="" id="loan_term_month" value="" />
<span class="input-field__hint">months</span>
</div>
<div class="input-hints row">
Expand Down Expand Up @@ -173,14 +173,14 @@
<p class="input__title">Loaned Fees</p>
<div class="input-field row">
<span class="input-field__hint">$</span>
<input type="text" class="input-field__input" placeholder="0" id="loaned_fees" value="" />
<input type="text" class="input-field__input" placeholder="" id="loaned_fees" value="" />

</div>
</label> <label class="input col ">
<p class="input__title">Upfront Fees</p>
<div class="input-field row">
<span class="input-field__hint">$</span>
<input type="text" class="input-field__input" placeholder="0" id="upfront_fees" value="1000" />
<input type="text" class="input-field__input" placeholder="" id="upfront_fees" value="1000" />

</div>
</label> </div>
Expand All @@ -192,7 +192,7 @@
<p class="input__title">House Value</p>
<div class="input-field row">
<span class="input-field__hint">$</span>
<input type="text" class="input-field__input" placeholder="0" id="house_value" value="350000" />
<input type="text" class="input-field__input" placeholder="" id="house_value" value="350000" />

</div>
<div class="input-hints row">
Expand All @@ -206,7 +206,7 @@
<p class="input__title">Down Payment</p>
<div class="input-field row">

<input type="text" class="input-field__input" placeholder="0" id="down_payment" value="20" />
<input type="text" class="input-field__input" placeholder="" id="down_payment" value="20" />
<span class="input-field__hint">%</span>
</div>
<div class="input-hints row">
Expand All @@ -222,7 +222,7 @@
<p class="input__title">Interest Rate</p>
<div class="input-field row">

<input type="text" class="input-field__input" placeholder="0" id="interest_rate_2" value="5.5" />
<input type="text" class="input-field__input" placeholder="" id="interest_rate_2" value="5.5" />
<span class="input-field__hint">%</span>
</div>
<div class="input-hints row">
Expand All @@ -236,7 +236,7 @@
<p class="input__title">Loan Term</p>
<div class="input-field row">

<input type="text" class="input-field__input" placeholder="0" id="loan_term_year_2" value="10" />
<input type="text" class="input-field__input" placeholder="" id="loan_term_year_2" value="10" />
<span class="input-field__hint">years</span>
</div>
<div class="input-hints row">
Expand All @@ -252,14 +252,14 @@
<p class="input__title">Loan Fees</p>
<div class="input-field row">
<span class="input-field__hint">$</span>
<input type="text" class="input-field__input" placeholder="0" id="loan_fees" value="3000" />
<input type="text" class="input-field__input" placeholder="" id="loan_fees" value="3000" />

</div>
</label> <label class="input col ">
<p class="input__title">Points</p>
<div class="input-field row">

<input type="text" class="input-field__input" placeholder="0" id="points" value="0.5" />
<input type="text" class="input-field__input" placeholder="" id="points" value="0.5" />

</div>
</label> </div>
Expand All @@ -268,7 +268,7 @@
<p class="input__title">PMI Insurance</p>
<div class="input-field row">
<span class="input-field__hint">$</span>
<input type="text" class="input-field__input" placeholder="0" id="pmi_insurance" value="" />
<input type="text" class="input-field__input" placeholder="" id="pmi_insurance" value="" />
<span class="input-field__hint">per year</span>
</div>
</label> </div>
Expand Down

0 comments on commit 054fe6b

Please sign in to comment.