Can someone please help me with this project I am working on? I want to select either one of the two divs (KgDiv, LDiv) by clicking it, then use the slide bar to select a value between 0 and the maximum value of the Kilograms/ Liters paragraph, then use the Sell button to convert Kg or L to € at a rate of 1 to 1. Also the quantity (kg or l) selected using the slide var should be displayed next to the slide bar.
var KilogramsV = 0;
var LitersV = 0;
function AddKg() {
KilogramsV += 400;
document.getElementById("Kilograms").innerHTML = KilogramsV + " " + "Kilograms";
}
function AddL() {
LitersV += 340;
document.getElementById("Liters").innerHTML = LitersV + " " + "Liters";
}
<div id="KgDiv">
<p id="Kilograms">Kilograms</p>
<input type="button" onClick="AddKg()" value="+400Kg"></input>
</div>
<div id="LDiv">
<p id="Liters">Liters</p>
<input type="button" onClick="AddL()" value="+340L"></input>
</div>
<input type="button" onClick="Sell()" value="Sell"></input>
<p id="Money">€ 0</p>
<input id="SlideBar" type="range" min="0" max="100" value="50"></input>
This is what I have so far.
Thanks!
I have watched yt videos but couldn’t find anything helpful.
2
Answers
I really didn’t get what you were trying to say. All I added to your code was that it shows the value of the slider under the slider. Please reply to this and tell me when else you need. Also, if this helped, mark this as the correct answer.
To achieve your goal, we should be modifying your code and add some more JavaScript.
What these codes do?
selectType(type)
function sets which type of unit is active and prints it to the end user.updateSliderMax(maxValue)
function updates the max value of the slider based on the selected type’s total amount and resets the slider and selected quantity display.updateQuantity(value)
function updates the text next to the slider to display the currently selected quantity along with the correct unit (Kg or L).sell()
function converts the selected quantity into euros at a 1:1 rate and updates the "Money" paragraph to display the total amount in euros.