mirror of
https://github.com/Max-Stevenson/jurassic-park-interface.git
synced 2024-06-17 08:29:31 +00:00
Refactor of existing voltage puzzle code.
- Added functionality to breaker button.
This commit is contained in:
parent
19fedb606a
commit
dbffc342d5
|
@ -30,6 +30,7 @@
|
|||
<p>High</p>
|
||||
<div class="toggle-switch switch-vertical">
|
||||
<input
|
||||
checked
|
||||
class="toggle-high"
|
||||
type="radio"
|
||||
name="switch-one"
|
||||
|
@ -51,6 +52,7 @@
|
|||
<p>High</p>
|
||||
<div class="toggle-switch switch-vertical">
|
||||
<input
|
||||
checked
|
||||
class="toggle-high"
|
||||
type="radio"
|
||||
name="switch-two"
|
||||
|
@ -72,10 +74,11 @@
|
|||
<p>High</p>
|
||||
<div class="toggle-switch switch-vertical">
|
||||
<input
|
||||
checked
|
||||
class="toggle-high"
|
||||
type="radio"
|
||||
name="switch-three"
|
||||
value="50"
|
||||
value="60"
|
||||
/>
|
||||
<input
|
||||
class="toggle-low"
|
||||
|
@ -93,6 +96,7 @@
|
|||
<p>High</p>
|
||||
<div class="toggle-switch switch-vertical">
|
||||
<input
|
||||
checked
|
||||
class="toggle-high"
|
||||
type="radio"
|
||||
name="switch-four"
|
||||
|
@ -113,7 +117,7 @@
|
|||
</div>
|
||||
<div class="power-screen__votage-output-container">
|
||||
<p>Required voltage: 220V</p>
|
||||
<p>Current voltage: <span id="current-voltage"></span></p>
|
||||
<p>Current voltage: <span id="current-voltage"></span>V</p>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
|
|
|
@ -29,20 +29,38 @@ document.getElementById("start-timer").addEventListener("click", () => {
|
|||
const voltageDisplay = document.getElementById("current-voltage");
|
||||
const voltageToggleInputs = document.querySelectorAll('input[type="radio"]');
|
||||
|
||||
const updateVoltage = () => {
|
||||
let totalVoltage = 0;
|
||||
for (let i = 0; i < voltageToggleInputs.length; i++) {
|
||||
if (voltageToggleInputs[i].checked) {
|
||||
totalVoltage += parseInt(voltageToggleInputs[i].value);
|
||||
}
|
||||
}
|
||||
voltageDisplay.innerHTML = totalVoltage;
|
||||
};
|
||||
|
||||
for (let i = 0; i < voltageToggleInputs.length; i++) {
|
||||
voltageToggleInputs[i].addEventListener("click", event => {
|
||||
let totalVoltage = 0;
|
||||
for (let i = 0; i < voltageToggleInputs.length; i++) {
|
||||
if (voltageToggleInputs[i].checked) {
|
||||
totalVoltage += parseInt(voltageToggleInputs[i].value);
|
||||
}
|
||||
}
|
||||
voltageDisplay.innerHTML = totalVoltage + "V";
|
||||
updateVoltage();
|
||||
});
|
||||
}
|
||||
|
||||
updateVoltage();
|
||||
|
||||
////////////////////////
|
||||
|
||||
// Breaker code
|
||||
chargeButton = document.getElementById("power-charge");
|
||||
chargeStatus = document.getElementById("charge-status");
|
||||
chargeButton.addEventListener("click", () => {
|
||||
let currentVoltage = parseInt(voltageDisplay.innerHTML);
|
||||
if (currentVoltage === 220) {
|
||||
chargeStatus.innerHTML = "Charged"
|
||||
}
|
||||
});
|
||||
////////////////////////
|
||||
|
||||
|
||||
// Control panel buttons
|
||||
const topControlPanelButtons = document.getElementsByClassName(
|
||||
"control-panel__button-display"
|
||||
|
|
Loading…
Reference in New Issue
Block a user