vendredi 31 mai 2019

How to write if-statement and document.write in function?

I'm new to Java and I'm stuck with this task. The task is to aks a user his name and save it in var name and do the same for exam and save it in var exam. Then I have to check what grade did student got on the exam and depending on answer (1, 2, 3, 4 or 5) write a message (if student got a grade 1 the message should be "Student (name) got (grade) on (exam)." I need to do that in Croatian and we have different form of verb for male and female version, I wrote that in code. I'm sorry if it's not clear but I don't know how to explain better.


<html lang="hr">
<head>
<meta charset="UTF-8">
<title>Task</title>
</head>
<body>

    <form>

        <p>NAME</p>
        <input id="name" type="text" name="Name" size="40" maxlength="150">
        <p>EXAM</p>
        <input id="exam" type="text" name="Exam" size="40" maxlength="150">
        <p>GENDER</p>
        <input id="gender" type="text" name="Gender" size="40" maxlength="150">
        <p>GRADE</p>
        <input id="grade" type="number" name="Grade" size="40">
        <input class="document" type="submit" onclick="task();">
        <p id="task"> </p>

        </form>
    <script>


        function task(){
            var grade= document.getElementById(grade).value;
            var name= document.getElemenetById("name");
            var exam= document.getElemenetById("exam");
            var gradetxt= [];
            var gender= document.getElemenetById("gender");


            if (grade == 1) {
                ocjenatxt = "insufficient";
            } else if (grade == 2) {
                ocjenatxt = "sufficient";
            } else (grade == 3) {
                ocjenatxt = "good";
            } else (grade== 4) {
                ocjenatxt = "very good";
            } else (grade== 5) {
                ocjenatxt = "excellent";
            }
            if (gender== "f" && grade== 1) {
                document.write("Studentica " + name+  " je na ispitu " + exam+ " pala."); /*this is for grade 1 for female (insufficient)*/
                } else if (gender == "m" && grade== 1); {
                   document.write("Student " + name + " je na ispitu " + exam+ " pao.");  /*this is for grade 1 for male (insufficient)*/
                } else (gender == "m" && grade != 1) {
                   document.write("Student " + name +  " je na ispitu " + exam + " ostvario ocjenu " + gradetxt);  /*this is for grade 2-5 for male (it should be written in words not number)*/
                } else (gender == "f" && grade != 1) {
                   document.write("Studentica " + name + " je na ispitu " + exam + " ostvarila ocjenu " + gradetxt);  /*this is for grade 2-5 for female (it should be written in words not number)*/
                }


        </script>

    </body>
</html>```

Aucun commentaire:

Enregistrer un commentaire