You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constbuttons=document.querySelectorAll(".button");constbody=document.querySelector("body");buttons.forEach(function(button){button.addEventListener("click",function(e){// code to change the color of the body goes hereconsole.log(e.target);// if (e.target.id == "grey") {// body.style.backgroundColor = "grey";// }switch(e.target.id){case"grey":
body.style.backgroundColor="grey";break;case"white":
body.style.backgroundColor="white";break;case"blue":
body.style.backgroundColor="blue";break;case"yellow":
body.style.backgroundColor="yellow";break;default:
body.style.backgroundColor="white";break;}});});
BMI Calculator
constform=document.querySelector("form");form.addEventListener("submit",function(e){e.preventDefault();constheight=parseInt(document.querySelector("#height").value);constweight=parseInt(document.querySelector("#weight").value);constresults=document.querySelector("#results");if(height===""||height<0||isNaN(height)){results.innerHTML=`Give an valid height ${height}`;}elseif(weight===""||weight<0||isNaN(weight)){results.innerHTML="Give an valid weight";}else{constbmi=(weight/((height*height)/10000)).toFixed(2);if(bmi<18.5){results.innerHTML=`Your BMI is ${bmi}, so you are underweight.`;}elseif(bmi>=18.5&&bmi<25){results.innerHTML=`Your BMI is ${bmi}, so you have a normal weight.`;}elseif(bmi>=25&&bmi<30){results.innerHTML=`Your BMI is ${bmi}, so you are overweight.`;}elseif(bmi>=30){results.innerHTML=`Your BMI is ${bmi}, so you are obese.`;}}});