English 中文(简体)
IMC 转换计算器
原标题:IMC Calculator with switch
  • 时间:2023-07-19 02:44:33
  •  标签:
  • javascript
I was working in a IMC calculator to exercise js. This calculator should shows the IMC and a message acording the result but, for some reason, it always shows the default message.

    

const form = document.querySelector( #form );
    
    
    form.addEventListener( submit ,(e)=>{
        e.preventDefault();

    const weight = document.querySelector( #weight ).value;
    const height = document.querySelector( #height ).value;

    const bmi = (weight / (height **2)).toFixed(2);


    const value = document.querySelector( #value );
    let description =   ;

    document.querySelector( #infos ).classList.remove( hiden );

    
    switch(bmi){
        case bmi < 18.5:
            description =  Cuidado! Você está abaixo do peso! ;
            break;
        case bmi >= 18.5 && bmi <= 25:
            description = "Você está no peso ideal!";
            value.classList.remove( attention );
            value.classList.add( normal );
            break;
        case bmi > 25 && bmi <= 30:
            description = "Cuidado! Você está com sobrepeso!";
            break;
        case bmi > 30 && bmi <= 35:
            description = "Cuidado! Você está com obesidade moderada!";
            break;
        case bmi > 35 && bmi <= 40:
            description = "Cuidado! Você está com obesidade severa!";
            break;
        case bmi > 40:
            description = "Cuidado! Você está com obesidade morbida!";
            break;
        default:
            description = "verifique novamente";
            break;
        }
    value.textContent = bmi.replace( . ,  , )
    document.querySelector( #description ).textContent =description ;
   
});

我试图改写,在类似“gt”的情况下使用母体(bmi > 25 &&bmi <=30)并检查家务劳动指示。 Algo seak in yt ook for some tutorial usingchange, but don t found any.

问题回答

你们正在转手处理一些案件,但所有案件都评估为渔民,因此他们永远能够相匹配。 您可使用一系列<代码>if,else [,和le

或者,转录在<代码>true上,这将造成第一起对true进行评价的情况。

switch (true) {
    // ...
}




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签