(Untitled)

Sep 23, 2009 22:34

I'm taking Javascripting this semester, and I've been stressing out about this one program for over a week. I'm just *not* getting it. It was due on Sunday, and I totally blew through the deadline, and I've been meaning all week to write my professor to apologize and ask if I can get some more help with this. "Just explain it to me like I'm ( Read more... )

tech support, w00t!, school

Leave a comment

Comments 4

(The comment has been removed)

kar3ning September 24 2009, 20:15:32 UTC
I think I've got the logic right, but I can't work out how to write the function.

I don't have my book with me, so I'm strangling the syntax, but the script is sort of like this:

----------------

var namelist = new Array

var name = prompt("Type a name.")

function feckingworkalready()

{

if (name) is (any series of characters)

{

1. add it to the "namelist" array in such a way that it can be found again.

2. ask the user for another name

3. repeat the loop

}

if (name) is "exit"

{

1. stop asking for names

2. go on to the rest of the script (break)

}

namelist.sort()

document.write("Here's your list." + "< br >")

document.write(namelist + "< br >")

------------

The first bit is giving me trouble. I can make it work if I populate the array beforehand (var namelist = new Array("Aragorn", "Gandalf", "Frodo") ), and I can figure out how to put one value in the array, but I can't work out how to make it 1. repeat and 2. find the names again to sort them.

Reply


ipsin September 24 2009, 23:46:51 UTC
You want to push() values into your array. You want to continue doing that until you see "exit". You need a loop!

Reply

(The comment has been removed)

ipsin September 24 2009, 23:49:07 UTC
ipsin September 24 2009, 23:50:31 UTC
Though of course the weakness of this is that "exit" is on your list, but... that's the idea. Too lazy to fix.

Reply


Leave a comment

Up