Jump to content

problem with if


MrAdam

Recommended Posts

well i been having a lot of javascript problems since i started learning.. and they come about when i start using if statements. for example i made this. i have no clue whats wrong here but it wont work :S

<script type="text/javascript">function test() {var test = alpha; If (test == "alpha") {     document.write("YAY!"); }}</script>

very simple.. yet it wont work :S

Link to comment
Share on other sites

well i been having a lot of javascript problems since i started learning.. and they come about when i start using if statements. for example i made this. i have no clue whats wrong here but it wont work :S
<script type="text/javascript">function test() {var test = alpha; If (test == "alpha") {     document.write("YAY!"); }}</script>

very simple.. yet it wont work :S

Just change the linevar test = alpha;By var test = "alpha";Because in the first case variable test is assign the value of variable alpha which is any random value.bye
Link to comment
Share on other sites

still not getting my yay tho :S

r u using only this code or other event to call this function?Because ur function should gt invoked by some eventOkif u want to see the result do the following
<script type="text/javascript">	var test = "alpha";	if(test=="alpha") 	{      document.write("YAY!");	}</script>

Note that "I" of if is small and not Big;Or Put a button in the html page and onclick event of that button call the function

<script type="text/javascript">function test() {	var test = "alpha";	if(test=="alpha") 	{      document.write("YAY!");	}}</script>

If u don't want to introduce html try the first code

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