Jump to content

Variable problem


Fire Dragon

Recommended Posts

Hi!I now try learn variables with w3schools tutorial,and book,what I got from library.Okay,I tried make variable,what grows,when you press button.And when it is "52",message appears to screen.However,it won't work.Here is my code:

<html><head><script type="text/javascript">var mutu = "50"if (mutu == "52"){document.write("Onnistui!")}</script><script type="text/javascript">function add()mutu++;</script><script type="text/javascript">document.write (mutu);</script><form><input type="button" onclick="add()" value="Lisää"></form>

What is wrong?

<script type="text/javascript">function add()mutu++;</script>

In this function,I tried set variable increase using mutu++; andmutu = mutu + 1;but it won't work.Can anybody help me what is wrong,so I can learn this variable thing?Thanks.

Link to comment
Share on other sites

Hi Why do you want to write in bits and pieces, write it togeather in one function,<script type="text/javascript">var mutu=50function cnt(){mutu=mutu+1if(mutu == 52){document.write("reached 52")}}</script><form><input type="button" onclick="cnt()" value="Lisää"></form>

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...