/    Sign up×
Community /Pin to ProfileBookmark

javascript disaster

Below is code that I have been working on for the past two days. The problem is it won’t work and I can’t figure out why. Somebody help me please?

[code]

<html>
<head>
<title>Array Practice</title>

<style type = “text/css”>
table { width: 10em }
th { text-align: left }

</style>

<script type=”text/javascript”>
<!–

var n1= new Array(5);
var n2= new Array();

for (var i=0; i < n1.length; ++1)
n1[ i ]=i;

for ( var i = 0; i < 5; ++i)
n2[ i ]=i;

outputarray(“Array n1:”, n1);
outputarray(“Array n2:”, n2);

function outputarray(heading, thearray)

{
document.writeln(“<h2>” + “heading” + “</h2>”);
document.writeln(“<table border = “1”>”);
document.writeln(“<th>Subscript</th>” + “<th>Value</th>”);

for ( var i = o; i < thearray.length; i++)
document.writeln(“<tr><td>” + i + “</td><td>” + thearray[i]+ “</td></tr>”);
document.writeln(“</table>”)
}
//–>
</script>
</head>
</html>
[/code]

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@Logic_AliSep 08.2008 — Below is code that I have been working on for the past two days. The problem is it won't work and I can't figure out why[/quote]It would be easy to point to the errors, but instead read the error messages in the console (preferably under FireFox), that's why they're provided.
Copy linkTweet thisAlerts:
@rfullerauthorSep 08.2008 — Ummmm.....we haven't reached that chapter yet. We've been writing codes using notepad or wordpad and testing them with Internet Explorer. You know the oldfashion method. And you can stop laughing now.
Copy linkTweet thisAlerts:
@Logic_AliSep 08.2008 — Ummmm.....we haven't reached that chapter yet. We've been writing codes using notepad or wordpad and testing them with Internet Explorer. You know the oldfashion method. And you can stop laughing now.[/QUOTE]That's irrelevant. Referring to the console should have been covered during the first lesson, just after everyone typed-in the first example program.

I.E.'s 'console' is pitifully inadequate, but still indicates the first error encountered. If you only have I.E. (bad idea) click on that yellow triangle in the bottom left corner.
Copy linkTweet thisAlerts:
@rfullerauthorSep 08.2008 — Thanks, you learn something new everyday.
Copy linkTweet thisAlerts:
@KorSep 08.2008 — Below is code that I have been working on for the past two days. The problem is it won't work and I can't figure out why. Somebody help me please?
[/QUOTE]

Another lesson: When you ask for help, you must give us the relevant data and specify the problem. You should have written something like: "My code supposes to do [I]this[/I], but instead it does [I]that[/I]". Otherwise how could we know what is wrong? It is not enough to say "My code does not work"; you must specify [I]what[/I] was your code doing (or supposes to do), and [I]which[/I] is the error you get now.
Copy linkTweet thisAlerts:
@Kostas_ZotosSep 08.2008 — Hi all,

In general Kor and Logic Ali are right ?

I'd like to report 2 points-errors [B](shown in red) [/B] that may help:


[B]1) [/B]Replace the 1 (one) with i

[CODE]for (var i=0; i < n1.length; ++[COLOR="Red"]1[/COLOR]) [COLOR="Green"] // Not 1 (shown in red), use i[/COLOR]
n1[ i ]=i;[/CODE]


[B]2) [/B]Replace the o with 0 (zero)
[CODE]for ( var i = [COLOR="Red"]o[/COLOR]; i < thearray.length; i++) [COLOR="Green"]// Replace the o (shown in red) with 0 (zero)[/COLOR]
document.writeln("<tr><td>" + i + "</td><td>" + thearray[i]+ "</td></tr>");[/CODE]

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

Also maybe here:

If want to print the headings passed as argument, then need to remove the quotes from "heading"
[CODE]document.writeln("<h2>" + [COLOR="Red"]"[/COLOR]heading[COLOR="Red"]"[/COLOR] + "</h2>"); [COLOR="Green"]// Remove the quotes, if want to use [B]heading[/B] as variable[/COLOR][/CODE]

May also exist other "errors", depends -as Kor said- on what you want your code to do

Regards!

Kostas
×

Success!

Help @rfuller 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 4.30,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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