Jump to content

Help with function that gives text random color


Masuen

Recommended Posts

Hi!

Im trying to add a function that gives the text in my code a random background color (either yellow, red or green).

I want this random color change to happen when I press the button.

Can anyone help me with this?

my code sofar is:

<!DOCTYPE html>
<html>
<body>

<p id="output_paragraph">Click the button to change the text in this paragraph.</p>


<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
  document.getElementById("output_paragraph").innerHTML = "Hello World";
 
}
</script>

</body>
</html>

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...