Jump to content

step zero js


ronald

Recommended Posts

hello,

 

i tried to build a very simple function, and i failed allready. dissapointing. I can not find where i went wrong. plz help me.

 

button 1: it should change the wordt "haai" to "yoyo" and then to "hallo". it does change haai to yoyo, but not beyond.

button 2: it should change color (it does, so works fine).

 

regards, ronald

 

<script>
function hello() {
var x = document.getElementById("hey");
if(x = "haai"){
var y = "yoyo";
}else{
var y = "hallo";
}
document.getElementById("hey").innerHTML = y;
}
function red(){
document.getElementById("hey").style.color = "red";
}
</script>
<button onClick="hello()">click me</button>
<button onClick="red()">click me</button>
<p id="hey">haai</p>
Link to comment
Share on other sites

<!DOCTYPE html><html lang="nl"><head><meta charset="utf-8"><title>tab</title></head><body><button onClick="hello()">click me</button><button onClick="red()">click me</button><p id="hey">haai</p><script>    function hello() {        var x = document.getElementById("hey").innerHTML;        if(x == "haai"){          var y = "yoyo";        }else{          var y = "hallo";        }        document.getElementById("hey").innerHTML = y;    }    function red(){        document.getElementById("hey").style.color = "red";    }</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...