Jump to content

Is that you, god?


Golanlan

Recommended Posts

I was just messing around, and I can't find what's the reason for the error here.

<html><head><script type="text/javascript">function disp_prompt(){ var name=prompt("Please enter your name","")  if (name!=null && name!="" && name!="God" && name!="god")  {   document.write("Hello " + name + "! How are you today?")  }  else if (name="God" && name="god")  {   document.write("OMFG IS THAT YOU?!?")  {  else  {   document.write("wtf are you doing?")  }}</script></head><body><form><input type="button" onclick="disp_prompt()" value="Display a prompt box"></form></body></html>

Link to comment
Share on other sites

I was just messing around, and I can't find what's the reason for the error here.
<html><head><script type="text/javascript">function disp_prompt(){ var name=prompt("Please enter your name","")  if (name!=null && name!="" && name!="God" && name!="god")  {   document.write("Hello " + name + "! How are you today?")  }  else if (name="God" && name="god")  {   document.write("OMFG IS THAT YOU?!?")  {  else  {   document.write("wtf are you doing?")  }}</script></head><body><form><input type="button" onclick="disp_prompt()" value="Display a prompt box"></form></body></html>

as I've seen u have few mistakes... and I didn't saw everything so u might have even more...first.. when u have few statements in if u should have it like that if ((one!="")&&(two!="")||(three="s"))and second if u wanna check if something equals to something u dont use = but == cause with only 1 = u put the value ur comparing to in the variable and check nothing...fix those and see if everything's ok :)
Link to comment
Share on other sites

<html><head><script type="text/javascript">function disp_prompt(){var name=prompt("Please enter your name","")  if (name=="God" || name=="god" || name=="GOD")  {   document.write("OMFG IS THAT YOU?!?")  }  else if (name!=="" && name!==" ")  {   document.write("Hello " + name + "! How are you today?")  }  else  {   document.write("wtf are you doing? Go backwords and FIX IT!")  }}</script></head><body><form><input type="button" onclick="disp_prompt()" value="Display a prompt box"></form></body></html>

Fixed, thanks :)By the way, would you know by any chance how can I keep with the banning of the spaces like here-

  else if (name!=="" && name!==" ")  {   document.write("Hello " + name + "! How are you today?")  }

automaticly that will forbit all numbers of spaces inserted?

Link to comment
Share on other sites

use this

name = trim(name);//.....else if(name.length < 1){   document.write("Hello " + name + "! How are you today?")}//function to trim spaces from the beginnning//and end of a stringfunction trim(str) { 	str.replace(/^\s*/, '').replace(/\s*$/, '');    return str;}

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