/    Sign up×
Community /Pin to ProfileBookmark

help debug please

   Alright, first off, I thank anyone who looks at this code and tries
to help me out in advance. Anywho, pretty much this script was
developed for me to study my German vocab easier and faster. It
worked out great to start, but than I started making it more user
friendly. I did a little something to tweak it a bit, and now it
just messes up. It works like this:

1) Asks you what language you are studying (this doesn’t really do
    much)

2) Asks how many words you need to study

3) Declares the arrays (English and German)

4) The loop begins

5) Asks for the English word and stores in English array

6) Asks for the previously declared language word for the english

    word and stores it in the German Array

7) Stores all the words in a variable with an ‘=’ seperating the
    English word from the foriegn language one

8) Loop ends

9) Displays confirm box, with OK being to go on and CANCEL being
    start over, with all the words displayed

10) Script ends

    Also, anytime a prompt comes up, you can hit the cancel button
or leave it empty to quit, or start over. Now for the problem,
after you type in the first English word and hit enter, or ok, the
script stops running. I thought maybe I inserted and extra ‘}’ to
stop the function, but I don’t see how that would be, since an
error would than occur. I use the latest IE browser, so if the
script has an error it alerts me, and I do not get one.

    Well here is the code:

<script language=”Javascript”>
<!–
function set()
{
var exit=5;
var wrds=”;
var l=prompt(‘What language are you studying for?’,’German’);

if ((l==null)||(l==”)||(l==’ ‘)){
set();}

var y=prompt(‘How many words?’,”);
if (y<1){
if (confirm(‘OK = Quitn Cancel = Start Over’)){
return -exit;}else{
set();}}

alert(y);
//declares arrays and length
var english=new Array(y);
var german=new Array(y);

for (var x=1;x<=y+1;x++)
{

english[x]=prompt(‘What is English word number ‘+x+’?’,”);

//verifies something is entered and if to quit
if ((english[x]==null)||(english[x]==”)||(english[x]==’ ‘)){
if (confirm(‘ OK= Quitn Cancel = Start Over’)){
alert(english[x]);
return -x;
break;
}else{
set();
}}

german[x]=prompt(‘What is the ‘+w+’ word for ‘+english[x]+’?’,”);

//verifies something is entered and if to quit
if ((german[x]==null)||(german[x]==”)||(german[x]==’ ‘)){
if (confirm(‘ OK= Quitn Cancel = Start Over’)){
return -x;
break;
}else{
set();
}}

wrds=wrds+english[x]+’ = ‘+german[x]+’n’;

}
alert(english[0]/german[0]);

if(confirm(‘English = Germannn’+wrds)){
game();
}else{
set();
}
}
–>
</script>

If you want to see the whole thing in action go to [url]http://svenssonr.tripod.com/act.htm[/url].

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@pj59Dec 19.2004 — Hello!

This line:

german[x]=prompt('What is the '+[COLOR=red]w[/COLOR]+' word for '+english[x]+'?','');

should be:

german[x]=prompt('What is the '+[COLOR=lime]l[/COLOR]+' word for '+english[x]+'?','');

and this line:

alert(english[0]/german[0]);

doesn't make sense. You are trying to do maths (division) with two undefined array elements. You are defining your array elements starting from 1 and not from 0; besides that: even if you would start with 0 they would be strings and not numbers and dividing strings will return NaN.

Regards PJ
Copy linkTweet thisAlerts:
@myndauthorDec 19.2004 — Hey thx man.



Yeah, I did mean the 'l' instead of the 'w', and on the alert(english[0]/german[0]); I meant to put alert(english[x]ngerman[0]);
Thank you for your help. I have been looking over this for about 3 or 4 days now, and have been stumped. I will try it out and inform you if it works or not. Thx agian


Mynd
Copy linkTweet thisAlerts:
@myndauthorDec 19.2004 — it does work, all because of the 'w' was in the place of the 'l'. Oh and for the last alert i remembered that the n has to be in quotes too. Well thx again man.

Mynd
×

Success!

Help @mynd spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...