Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions calculator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
var inputRadius;
var inputHeight;
var volume = document.getElementById("volume");
var baseArea = document.getElementById("baseArea");
var sideArea = document.getElementById("sideArea");
var totalArea = document.getElementById("totalArea");

window.onload = function(){
performTest();
document.getElementById("radius").addEventListener("change", getResults);
document.getElementById("height").addEventListener("change", getResults);
}

function performTest(){
const cyl = new Cylinder(3,4);
var testVolume = cyl.volume.toFixed(3);
var testTotalArea = (cyl.baseArea+cyl.sideArea).toFixed(3);
if(testVolume == "113.097" && testTotalArea == "103.673"){
document.getElementById("testResult").innerHTML = "Test successful";
}else{
document.getElementById("testResult").innerHTML = "TEST FAILED!";
}
}

function getResults(){
inputRadius = document.getElementById("radius").value;
inputHeight = document.getElementById("height").value;
const c = new Cylinder(inputRadius, inputHeight);
volume.innerHTML = c.volume.toFixed(3);
baseArea.innerHTML = c.baseArea.toFixed(3);
sideArea.innerHTML = c.sideArea.toFixed(3);
totalArea.innerHTML = (c.baseArea+c.sideArea).toFixed(3);

}

class Cylinder{
constructor(radius, height){
this.radius = radius;
this.height = height;
}
//volume
get volume(){
return this.calcVolume();
}

calcVolume(){
return Math.PI*Math.pow(this.radius, 2)*this.height;
}

//baseArea
get baseArea(){
return this.calcBaseArea();
}

calcBaseArea(){
return Math.PI*Math.pow(this.radius, 2);
}

//sideArea
get sideArea(){
return this.calcSideArea();
}

calcSideArea(){
return 2*Math.PI*this.radius*this.height;
}
}
24 changes: 24 additions & 0 deletions home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="et">
<head>
<meta charset="UTF-8">
<title>Silindri kalkulaator</title>

</head>
<body>
<p id="testResult"></p>
<h1>Silindri kalkulaator</h1>
<div style="display:flex;height:20px;align-items:center;margin-bottom:20px">
<p style="width:70px">Raadius: </p><input id="radius" type="number" step="0.1" value="0">
</div>
<div style="display:flex;height:20px;align-items:center">
<p style="width:70px">Kõrgus: </p><input id="height" type="number" step="0.1" value="0">
</div>
<p>Ruumala: <span id="volume"></span></p>
<p>Põhjapindala: <span id="baseArea"></span></p>
<p>Küljepindala: <span id="sideArea"></span></p>
<p>Täispindala: <span id="totalArea"></span></p>

<script src="calculator.js" charset="utf-8"></script>
</body>
</html>