Solve this. |
![]() ![]() |
Solve this. |
Sep 1 2009, 05:41 PM
Post
#1
|
|
![]() Senior Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Designer Posts: 5,880 Joined: Nov 2007 Member No: 593,382 |
My teacher showed me, but I forgot and cant find what it is called or how to solve it.
CODE function get_name(name) { // test to make sure it is a string that isn't empty // test to make sure that it is at least 3 characters long // test to make sure that it is either Paul, John or Bob and no one else alert("Hi " + name); } How can I tell it what name is? and it would be mice if someone could tell me how to tell it the name too. Something like: CODE var name = prompt("What is your name?",""); This is javascript btw. Not php. I keep getting confused too... I have watched all the lynda.com javascript tutorials and all the w3schools.com javascript tutorials and for some reason I cant solve this. Thanks. |
|
|
|
Sep 1 2009, 06:47 PM
Post
#2
|
|
![]() Senior Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Designer Posts: 5,880 Joined: Nov 2007 Member No: 593,382 |
I like php much better...
|
|
|
|
Sep 1 2009, 08:02 PM
Post
#3
|
|
![]() Senior Member ![]() ![]() ![]() ![]() ![]() ![]() Group: Administrator Posts: 2,648 Joined: Apr 2008 Member No: 639,265 |
I'm sure it could be done in a fancier (read: more concise) way, but this should work:
CODE function get_name(name) { if (name.length >= 3 && (name == "Bob" || name == "John" || name == "Paul")) { alert("Hi, " + name); } } Caveat: Didn't actually test it. |
|
|
|
Sep 1 2009, 08:54 PM
Post
#4
|
|
![]() Senior Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Designer Posts: 5,880 Joined: Nov 2007 Member No: 593,382 |
Darn. I didn't actually want you to do the whole thing! haha. That was my assignment!
But it actully didnt work. CODE <html> <head> <title>Script</title> <script type="text/javascript" src="names.js"></script> </head> <body> Hello World! </body> </html> Thats the page it is inserted into. I got no alert. |
|
|
|
Sep 1 2009, 09:53 PM
Post
#5
|
|
![]() Senior Member ![]() ![]() ![]() ![]() ![]() ![]() Group: Administrator Posts: 2,648 Joined: Apr 2008 Member No: 639,265 |
|
|
|
|
Sep 1 2009, 09:58 PM
Post
#6
|
|
![]() Senior Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Designer Posts: 5,880 Joined: Nov 2007 Member No: 593,382 |
O. I thought it did... haha.
CODE <html> <head> <title>Script</title> <script type="text/javascript" src="names.js"></script> <script type="text/javascript"> function get_name() </script> </head> <body> Hello World! </body> </html> Am i doing it right? They never taught me how to do this on w3schools or lynda.com. I need to look for practical javascript tutorials. |
|
|
|
Sep 1 2009, 10:02 PM
Post
#7
|
|
![]() Senior Member ![]() ![]() ![]() ![]() ![]() ![]() Group: Administrator Posts: 2,648 Joined: Apr 2008 Member No: 639,265 |
Am i doing it right? They never taught me how to do this on w3schools or lynda.com. I need to look for practical javascript tutorials. No:
You probably want to do it on page load, like this: CODE <!-- header stuff -->
<body onload='get_name("Bob");'> |
|
|
|
Sep 1 2009, 10:48 PM
Post
#8
|
|
![]() Senior Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Designer Posts: 5,880 Joined: Nov 2007 Member No: 593,382 |
ugh... but I thought that wasnt neccessary when you are using a external js file. I guess I have much t learn.
It works now. So my next question is, how can I do the equivalent of CODE <?php $name = "Joseph"; ?> <?php echo "My name is $name."; ?> Which will give the outcome: CODE My name is Joseph. How can I do the same thing in Javascript? |
|
|
|
Sep 2 2009, 12:08 AM
Post
#9
|
|
![]() Senior Member ![]() ![]() ![]() ![]() ![]() ![]() Group: Administrator Posts: 2,648 Joined: Apr 2008 Member No: 639,265 |
document.write() is (roughly) JavaScript's equivalent of PHP's echo.
|
|
|
|
Sep 2 2009, 04:45 AM
Post
#10
|
|
![]() Senior Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Designer Posts: 5,880 Joined: Nov 2007 Member No: 593,382 |
And whats equivalent to php variables.
|
|
|
|
Sep 2 2009, 04:54 AM
Post
#11
|
|
![]() Live long and prosper. ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Staff Alumni Posts: 10,142 Joined: Apr 2007 Member No: 514,926 |
Joseph, do you own work. Michaels not your monkey.
|
|
|
|
Sep 2 2009, 05:01 AM
Post
#12
|
|
![]() Senior Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Designer Posts: 5,880 Joined: Nov 2007 Member No: 593,382 |
I know. But I have no options left. and he is being very kind. I have watched two whole series of javascript tutorials and none of them tell me how to do this. Im just now trying to figure out how to tell it, what the name is.
|
|
|
|
Sep 2 2009, 05:24 AM
Post
#13
|
|
![]() Live long and prosper. ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Staff Alumni Posts: 10,142 Joined: Apr 2007 Member No: 514,926 |
I know. But I have no options left. and he is being very kind. I have watched two whole series of javascript tutorials and none of them tell me how to do this. Im just now trying to figure out how to tell it, what the name is. Couldn't you ask the people you're interning for? |
|
|
|
Sep 2 2009, 05:27 AM
Post
#14
|
|
![]() Senior Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Designer Posts: 5,880 Joined: Nov 2007 Member No: 593,382 |
I go in once a week. Thats why im asking micheal. And if he is kind enough to help me, please dont stop him. haha.
|
|
|
|
Sep 3 2009, 02:48 PM
Post
#15
|
|
![]() Senior Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Staff Alumni Posts: 4,095 Joined: Jul 2005 Member No: 171,080 |
how do you get an internship when you can't do shit
|
|
|
|
![]() ![]() |