home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

Beginner in Javascript I need help!!

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2010
Discussions: 200,950, Posts: 2,379,436, Members: 246,311
Old June 13th, 2008, 11:55 AM   Digg it!   #1 (permalink)
Junior Member
 
Join Date: Jun 2008
Posts: 4
Beginner in Javascript I need help!!

I have a class with a crap teacher I really need help with this as I cant get it to work. Here are the instructions.

The strings entered by the user are split at the space to give a two-element array, which is assigned to a new row in strs. Function check repeatedly prompts the user for a string and checks whether there is a pair in array strs that matches in the manner described above. It does this with a do/while loop. Index i starts at 0 and variable found is initialized to false. It goes through the rows in strs (indexed by i) until found becomes true or the rows are exhausted (i is equal to the length of strs).



Here is the code I have so far:
<html>
<head>
<script type=”text/javascript”>
var strs = new Array();
init( strs );
check( strs );
function init( strs )
{
while ( str = window.prompt(
"Enter a string with an initial and final segment"
+ " separated by a space",
"" ) )
strs=str.split(" ") ;
}

function check( strs )
{
while ( str = window.prompt( "Enter a string", "" ) )
{
var found = false,
i = 0;

do {
var loc1 = strs[i][0];
if ( loc1 != -1 ) {
var loc2 = strs[i][1]+ strs[i][0];
if ( loc2 != -1 )
found = true;
}
i++;
} while ( !found && strs.length>i );
if ( found )
alert("Found");
else
alert("Not found");
}
}
</script>
</head>
</html>
overdosed20 is offline   Reply With Quote
Old June 13th, 2008, 10:40 PM     #2 (permalink)
Super F@D Folder
 
Join Date: Jun 2004
Posts: 5,083
Send a message via AIM to sr71000
you should always put your code inside of code tags

[ code ]
your code here
[ /code ]

if you take out the spaces around the words code and /code you get

Code:
your code here
This will make it much easier for us to troubleshoot and help We don't like to give out answers with homework. If you want help, get started with the project and when you're stuck on something, as a more specific question. I know that I and others are glad to help but I know that at least I personally don't like to just give out answers.

-Kevin
sr71000 is offline   Reply With Quote
Old June 20th, 2008, 11:39 AM     #3 (permalink)
Junior Member
 
Join Date: Jun 2008
Posts: 4
I just can't figure out why nothing is displaying when I launch this from notepad.

Code:
<html>
<head>
<title>Quiz2</title>
<script type=”text/javascript”>
var strs = new Array();
init( strs );
check( strs );
function init( strs )
{
   while(str = window.prompt( 
                  "Enter a string with an initial and final segment"
                  + " separated by a space",
                  "" )) 
    
 strs=str.split(" ");
}
function check( strs )
{
  while ( str = window.prompt( "Enter a string", "" )  )  {
    var found = false,
        i = 0;
  
    do  {
      var loc1 = strs[i][0];
      if ( loc1 != -1 )  {
        var loc2 = strs[i][1]+ strs[i][0];

        if ( loc2 != -1 )
          found = true;
      }
      i++;
    } while ( !found && strs.length>i );
    if ( found )
      alert("Found");
    else
      alert("Not found");
  }
}
</script>
</head>
</html>
overdosed20 is offline   Reply With Quote
Old June 22nd, 2008, 10:01 PM     #4 (permalink)
Member
 
Join Date: Oct 2003
Posts: 263
change yoru javascript tag to the following:

your quotes are funky...once i changed them with the line below it ran through fine.


Code:
<script type="text/javascript">
amtrac24 is offline   Reply With Quote
Old June 22nd, 2008, 10:05 PM     #5 (permalink)
Member
 
Join Date: Oct 2003
Posts: 263
you need to fix your loops though.
amtrac24 is offline   Reply With Quote
Old June 22nd, 2008, 10:31 PM     #6 (permalink)
Member
 
Join Date: Oct 2003
Posts: 263
here you go buddy...

Code:
<html>
<head>
<title>Quiz2</title>
<script type='text/javascript'>
var strs = new Array();
strs=init( strs );
check( strs );

function init( strs )
{
var str='';

while (str=='')
{
   str = window.prompt( 
                  "Enter a string with an initial and final segment"
                  + " separated by a space",
                  "" )
}
  

 strs=str.split(" ");
 
 return strs;

}
function check( strs )
{
var str='';
var found = false;

while (str=='')
{
 	str = window.prompt( "Enter a string", "" ) 
}

	for (var i=0;i<strs.length;i++)
	{
		if (strs[i]==str)
		{
		   found=true;
		}
	}
	
	if (found)
		alert('Found');
	else
		alert('Not Found');
}
</script>
</head>
</html>
amtrac24 is offline   Reply With Quote
Old June 24th, 2008, 12:34 PM     #7 (permalink)
Junior Member
 
Join Date: Jun 2008
Posts: 4
Thanks Amtrack that worked great.
overdosed20 is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginner Javascript question James Engle Webmastering and Programming 0 April 21st, 2008 11:43 PM
Beginner, javascript code help! snikker74 Webmastering and Programming 4 April 4th, 2008 12:08 PM
Beginner needs help mewelch Motherboards 1 February 1st, 2007 10:29 PM
Beginner Guitar help............ Cyclone2 IMO Community 31 July 3rd, 2004 09:49 PM
im a beginner..... couch potato Webmastering and Programming 18 January 26th, 2003 09:44 PM


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
The disrespect of Obama by Russian .. (33)
Making Health Care Worse (176)
Is It Just Me? (2940)
Wireless Televisions. (12)
windows 7 problem (7)
CPU fan stops spinning randomly (8)
Regular Build (7)
radeon x850xt platinum & shader.. (6)
Is the PSU I received dead? (12)
Print spooler problem (15)
HIS HD5770 graphic card question (15)
Install XP pro and a Vista laptop ?.. (11)
windows vista security holes (9)
Dept. of HS: NSA 'Helped' Develop V.. (15)
Recent Discussions
Point and Shoot Camera Suggestions. (4)
Regular Build (7)
Multiple Restarts Required at Boot (2)
Ideal cheap graph card for PC-Gaming? (18)
radeon x850xt platinum & shader 3 (6)
Graphics Card Upgrade Question (4)
For Sale BFG GTX285 OC2 with 10 year .. (3)
How to convert MP3's (4)
Wireless Televisions. (12)
Laptop with wireless problem. (2)
Internet Lost (1)
Hp Artist Edition + Matching Bag (0)
My monitor won't turn on after instal.. (0)
Asus P4G8X Mobo (6)
Xbox 360 GTA: SA disk error (1)
Is the PSU I received dead? (12)
windows 7 internet problem (5)
BSOD On Startup (ntoskrnl.exe) (2)
Print spooler problem (15)
Have you switched yet? (86)
screen resolution vs monitor size (2)
sms storage to PC (0)
Open With ..... Win7 (0)
java code for fibonacci (1)
[F@H SPAM 11/16/09] ! 1/2 months to r.. (35)


All times are GMT -4. The time now is 11:30 PM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28