Need help with getElementByID in Project – JavaScript – SitePoint Forums

Hi all!

I’m new to Javascript and I’m taking a course. I have finished my homework and I hope it is correct.
I would REALLY appreciate your help!

My mission is the following:

  1. Create an if function that will display the result, with the following criteria:

a. If the user filled in their name in the prompt window, the paragraph with the id “result” should display the message “Hello STUDENT!” Your result is SCORE out of 10.

I. Replace STUDENT with the name the user entered in the prompt window.

ii. Replace SCORE with the user’s score.

b. If the user has not completed their name in the prompt window, the paragraph with the id “result” should display the message “Your result is SCORE out of 10”.

Replace SCORE with the user’s score.

Here is my project result.

I have an HTML file with paragraph id attribute.
Therefore, I created a variable with outputx and another with outputy. One is for a student’s entry and the other is unnamed.

From the HTML file.

var response = prompt(“What is your name?”);
var outputx = document.getElementById(“result”);
var outputy = document.getElementById(“result”);

var score1 = 10;

var response = prompt(“What is your name?”);
if (answer) {
outputx.innerHTML =
“Hello” + reply + “!. You have +score1+ out of 10.”;
}
if (response !=null) {
outputy.innerHTML =
“Your result is +score1+ out of 10.” ;
}


Comments are closed.