How to calculation gpa to grade

*I am using  if else method you can try other method*
````Now  i am declare  h1 tag and show  our gpa  grade `
so now declare
`<h1 id="demo"></h1>`
   let demo = document.getElementById('demo');
        let marks = prompt('Enter your number :');
        if(marks >=80){
            demo.innerHTML= 'A+';
        }else if( marks >=70){
            demo.innerHTML ='A';
        }else if(marks >=60){
            demo.innerHTML ='A-';
        }else if( marks >=50){
            demo.innerHTML ='B';
        }else if(marks >=40){
            demo.innerHTML ='C';
        }else if(marks >=33){
            demo.innerHTML ='D';
        }else{
            demo.innerHTML ='F';
        }

What exactly is your question?

Not question its solution

HI @farukbba0077 !

Welcome to the forum!

Posting solutions is meant to invite discussion.
But right now, we don’t have any context for this code.

This doesn’t look like a freecodecamp challenge.

Is this a project you are working on?
Are you looking for feedback on this code?

Can you provide more context?

Yes i want feedback and
i want to know this problem other kind solution

One thing you can look into is valid user input.

What happens if the user does not provide any input?
Or what happens if the user provides a strings like “apple”?

Right now your program would just accept that answer.

You could add a condition that says if the user input is not a number then an error message prompts them to enter a valid input.

how to use this condition ?
What happens if the user does not provide any input?
Or what happens if the user provides a strings like “apple”?

Well I think there are a few options.

You can write your own logic in javascript to test if it is a number.
You can play around with something like the type of operator

You can also play around with the isNaN()

But I think a better option would be to choose a different html tag.
Instead of using a h1 you can look into using a the number input.

That html tag already has built in validation.
It also allows you to set a min and max number input.
Then you can change your javascript code to grab the value of the input.
A short google search will show you how to grab the value from an input tag.

I think your current code works fine.
You are just assuming the user is going to comply.

I think a stronger program should ensure the user provides valid input.

Hope that helps!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.