/    Sign up×
Community /Pin to ProfileBookmark

Javascript Array Difficulties

[code=html]<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml”
xml:lang=”en”>

<head>

<title>::GUEST BOOK::</title>

<script type=”text/javascript”
language=”JavaScript 2.1″>
<!–

function main()
/**************************************
TITLE: Arrays Lab
AUTHOR: David W. Kelley (DWK)
CREATE DATE: October 25, 2006
PURPOSE: Display knowledge of arrays and compile the array data into a displayable form.
LAST MODIFIED ON: October 30, 2006
LAST MODIFIED BY: David W. Kelley (DWK)
MODIFICATION HISTORY:
Added webpage variable.
***************************************/

{
const STRDEFAULTTEXT = new String(“Type your answer here.”);

var GuestTotal = new Array();

var g = new Number(0);
var GuestNumber = new String();

var strQuestion = new String(“”);
var strGuestNames = new String(“”);
var strGuests = new String(“”);
var strOutputMsg = new String(“”);

do
{
strQuestion = “Good day! How many guests shall “;
strQuestion += “be attending.”;

GuestNumber = parseInt(window.prompt(strQuestion,”0″));

if(GuestNumber>10)
{
strOutputMsg = “My apologies. However, you ”
strOutputMsg += “cannot invite that many guests.”

window.alert(strOutputMsg);
}
}while(GuestNumber>10)

for(g=0;g<GuestNumber;g++)
{
strQuestion = “Wonderful! Now, then, please tell ”
strQuestion += “me the name of Guest #”
strQuestion += (g+1);
strQuestion += “.”;

GuestTotal = window.prompt(strQuestion,STRDEFAULTTEXT);
}
strOutputMsg = “Your guests are as follows:n”;
strOutputMsg += “#”;
strOutputMsg += strGuestTotal;

strWebpage = new Array(strOutputMsg);

window.document.write(strWebpage);

}//end main

// –>
</script>

</head>

<body onLoad=”javascript:main();”>

<h1 style=”text-align:center”>SCRIPT TITLE</h1>

<hr size=”2″
width=”85%” />

</body>

</html>[/code]

Okay, here’s the problem: I can get it to run in Mozilla Firefox fine.. except for the fact that ONLY the third name entry shows up.

I need to find a way to show all three names. I’d apprecitae any help thank you.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Arty_EffemNov 02.2006 — Okay, here's the problem: I can get it to run in Mozilla Firefox fine[/QUOTE]I don't see how do you manage that while referencing the non-existent variable [I]strGuestTotal[/I].
GuestTotal = window.prompt(strQuestion,STRDEFAULTTEXT);[/QUOTE][I]GuestTotal[/I] starts life as an array, but here you convert it to a string.
window.document.write(strWebpage);[/QUOTE]You cannot use document.write in a closed document.
Copy linkTweet thisAlerts:
@MasterRDnaauthorNov 02.2006 — I don't see how do you manage that while referencing the non-existent variable [I]strGuestTotal[/I].

[I]GuestTotal[/I] starts life as an array, but here you convert it to a string.

You cannot use document.write in a closed document.[/QUOTE]


I solved the problem; I made a mistaken when coding.

Anyway, thank you for your help! Looking at GuestTotal was the whole reason I even SOLVED the problem.
×

Success!

Help @MasterRDna 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.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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