Skip to content

Commit

Permalink
BENERAN FINAL
Browse files Browse the repository at this point in the history
  • Loading branch information
vinn005 committed Nov 7, 2024
1 parent d7107aa commit eab1d5d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
5 changes: 3 additions & 2 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ input[type=number] {
border-radius: 3px;
font-family: monospace;
font-size: 16px;
transition-duration: 0,4s;
}

#hitung-bmi:hover {
Expand All @@ -69,7 +70,7 @@ input[type=number] {
}

/* Style Button Reset */
#reset {
#tombol-reset {
background-color: white;
color: red;
border: 2px solid red;
Expand All @@ -80,7 +81,7 @@ input[type=number] {
transition-duration: 0.4s;
}

#reset:hover {
#tombol-reset:hover {
border: 2px solid red;
background-color: red;
color: aqua;
Expand Down
8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ <h1> Kalkulator BMI </h1>

<!-- Masukkan berat badan -->
<label for="berat-badan"> Berat Badan (kg) </label> <br>
<input id="berat-badan" type="number" min="1" required> <br> <br>
<input id="berat-badan" type="number" min="0" required> <br> <br>

<!-- Masukkan usia -->
<label for="usia"> Usia (tahun) </label> <br>
<input id="usia" type="number" min="1" required> <br> <br>
<input id="usia" type="number" min="0" required> <br> <br>

<!-- Masukkan tinggi -->
<label for="tinggi"> Tinggi (meter) </label> <br>
<input id="tinggi" type="number" min="1" max="2" required> <br> <br>
<input id="tinggi" type="number" min="0" max="2.5" required> <br> <br>
</div>
<button onclick='validateForm(); hitungBMI(event)' id="hitung-bmi"> Hitung BMI </button>
<button onclick='reload(event)' id="reset"> Reset </button>
<input type="reset" id="tombol-reset"></input>
</form>
</div>

Expand Down
17 changes: 4 additions & 13 deletions js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ function validateForm() {
let tinggiBadan = document.getElementById('tinggi').value;
let usiaSekarang = document.getElementById('usia').value;

// Kondisi Validasi jika form kosong
if (beratBadan == '' || tinggiBadan == '' || usiaSekarang == '' || parseInt(beratBadan, tinggiBadan, usiaSekarang) <= 1) {
// Kondisi validasi jika form kosong atau tidak sesuai kriteria
if (beratBadan == '' || tinggiBadan == '' || usiaSekarang == '') {
alert('Inputan Anda Tidak Valid'); document.getElementById('result info info2').innerHTML = '-'
} else if (tinggiBadan > 2.5) {
alert ('Inputan Anda Tidak Valid'); document.getElementById('result info info2').innerHTML = '-'
}
}

Expand Down Expand Up @@ -39,15 +41,4 @@ function hitungBMI(event) {
document.getElementById('info').innerHTML = 'Anda Kegemukan (Obesitas)'
document.getElementById('info2').innerHTML = 'Penting untuk berkonsultasi dengan dokter atau ahli gizi untuk mendapatkan panduan penurunan berat badan yang sesuai. Pola makan rendah kalori dan tinggi serat, bersama olahraga teratur, sangat direkomendasikan. Latihan aerobik, seperti berlari atau bersepeda, serta latihan kekuatan dapat membantu mengurangi lemak tubuh secara efektif. Dalam kasus tertentu, dokter mungkin menyarankan metode lain, seperti terapi, program penurunan berat badan, atau intervensi medis jika diperlukan.'
}
}

// Button reset
function reload(event) {
event.preventDefault;

if (beratBadan == '' || tinggiBadan == '' || usiaSekarang == '' || parseInt(beratBadan, tinggiBadan, usiaSekarang) <= 1) {
window.location.reload;
} else {
window.location.reload;
}
}

0 comments on commit eab1d5d

Please sign in to comment.