I looked through a few questions on here but none of them seems to be showing the problem that I am having.
The Problem:
I have a business case question where we are asked to build a simple calculator for a business pricing model using HTML/Javascript/CSS.
I'm still a beginner to these languages but have good experience in other languages.
I have been through google and stack overflow, all of which are telling me to use the "document.GetElementById()" function.
I have tried implementing this function however I must be doing something wrong because when I press submit nothing happens.
I apologise for the following being a long code block but I can't be sure where my error actually is.
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Business Case Calculator</title>
<script>
function displayTable() {
let boxStr = document.getElementById("number");
if (boxStr != '') {
numOfEmps = parseInt(boxStr);
if (numOfEmps < 1) {
numOfEmps = 1;
}
}
switch (true) {
case numOfEmps <= 12:
prices = bracket1(numOfEmps);
case numOfEmps <= 50:
prices = bracket2(numOfEmps);
case numOfEmps <= 250:
prices = bracket3(numOfEmps);
}
document.getElementById("mojo-price").innerHTML = String(prices[0]);
document.getElementById("wiredup-price").innerHTML = String(prices[1]);
document.getElementById("workwith-price").innerHTML = String(prices[2]);
document.getElementById("063-price").innerHTML = String(prices[3]);
document.getElementById("total-price").innerHTML = String(prices[4]);
function bracket1(numOfEmps) {
let mojo = 0;
let wiredUp = numOfEmps * 75;
let workWith = numOfEmps * 75;
let the063 = numOfEmps * 250;
let totalPrice = mojo + wiredUp + workWith + the063;
return [mojo, wiredUp, workWith, the063, totalPrice];
}
function bracket2(numOfEmps) {
let mojo = 0;
let wiredUp = numOfEmps * 60;
let workWith = numOfEmps * 60;
let the063 = numOfEmps * 200;
let totalPrice = mojo + wiredUp + workWith + the063;
return [mojo, wiredUp, workWith, the063, totalPrice];
}
function bracket3(numOfEmps) {
let mojo = 0;
let wiredUp = numOfEmps * 54;
let workWith = numOfEmps * 54;
let the063 = numOfEmps * 180;
let totalPrice = mojo + wiredUp + workWith + the063;
return [mojo, wiredUp, workWith, the063, totalPrice];
}
}
</script>
</head>
<body>
<div class="input">
<form class="input-form" id="cpcalc">
<input type="text" placeholder="30" id="number">
</form>
<button type="button" onclick="displayTable();">Submit</button>
</div>
<div>
<table>
<tr>
<td>
Profiler
</td>
<td>
Price
</td>
</tr>
<tr>
<td>
Mojo
</td>
<td>
<!--Mojo Price-->
<span id="mojo-price">
</span>
</td>
</tr>
<tr>
<td>
Wired Up
</td>
<td>
<!--Wired Up Price-->
<span id="wiredup-price">
</span>
</td>
</tr>
<tr>
<td>
Work With
</td>
<td>
<!--Work With Price-->
<span id="workwith-price">
</span>
</td>
</tr>
<tr>
<td>
063 | 360
</td>
<td>
<!--063 Price-->
<span id="063-price">
</span>
</td>
</tr>
<tr>
<td>
<!--Blank-->
</td>
<td>
<!--Blank-->
</td>
</tr>
<tr>
<td>
Total
</td>
<td>
<!--Total Price-->
<span id="total-price">
</span>
</td>
</body>
</html>
What I am hoping happens is that the table is populated with the calculated prices correctly.
I will be dealing with the CSS side of the question once the functionality works.