Computer Chess Club Archives


Search

Terms

Messages

Subject: Thanks! (NT)

Author: Graham Laight

Date: 04:07:04 01/04/03

Go up one level in this thread


On January 04, 2003 at 04:30:15, Alessandro Damiani wrote:

>On January 03, 2003 at 16:52:52, Graham Laight wrote:
>
>>On January 03, 2003 at 07:52:46, Graham Laight wrote:
>>
>>I've just tried the code below on an old computer at home running IE 5.0, and it
>>threw up an unexpected error which I've highlighted below. Perhaps someone with
>>more JavaScript experience than me (I'm learning it for my job) would like to
>>comment?
>>
>>><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
>>>
>>><html>
>>><head>
>>><title>Graham's Optimisation Demo</title>
>>></head>
>>><body>
>>><SCRIPT LANGUAGE="JavaScript">
>>>function easyToMaintain()
>>>{
>>> var R = new Array();
>>> R[0] = 1;
>>> R[1] = 2;
>>> R[2] = 3;
>>>
>>> var p = 0;
>>> var startTime = new Date();
>>>
>>> for (k = 0; k < 1000000; k++)
>>> {
>>> 	if((R[1]==3)||(R[1]==7))
>>>		p = p + 1;
>>> }
>>>
>>> var endTime = new Date();
>>> var totalTime = endTime.getTime() - startTime.getTime();
>>> alert("The easy to maintain version took " + totalTime + " milliseconds to
>>>run");
>>
>>Here. The CCC text editor has wrapped my quoted text onto 2 lines, which caused
>>an error (in IE5, to see a JavaScript error, click on the icon on the very
>>bottom left of the IE window after the error has occured).
>>
>>Spacing and line breaks are supposed to be unimportant in JavaScript -
>>presumably the problem is that the line break occurs in the middle of a quoted
>>text string.
>>
>
>In Java breaks are not allowed in strings. If a string has to be split up it has
>to be done manually by using the concatenator "+".
>
>In your case you already concatenate strings, so a break could be put just after
>'totalTime +':
>
>    alert("The easy to maintain version took " + totalTime +
>          " milliseconds to run");
>
>Alessandro



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.