/    Sign up×
Community /Pin to ProfileBookmark

Why aren’t reruns of this script on the next line?

In the following script (I’m trying to get away from using forms), each click should put a new test on the next line, but the output just continues at the end of the previous line. What am I missing? The newlines seem to be ignored.

[code]<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Spider Solitaire</title>
<script>
function sortCards(a,b) {return a – b;}
function genform() {
var deck = new Array(104);
var shuffle = new Array;
var countNull = 0;
for (var m = 0; m < 10000; m++) {
for (var i=0; i < 104;i++) { // New game done 1000 times
deck[i] = i % 13; // Will repeat 0 – 12 eight times
}
var j = 104;
for (var n = 0; n < 5;n++) { // Will draw five times per game}
var haveMove = false;
for (var k = 0; k < 10; k++) {
var r = Math.floor(Math.random() * (j+1)); // Pick one from those remaining
shuffle[k] = deck[r];
j–; }
shuffle.sort(sortCards);
for (var mm = 0;mm < 9;mm++) {
if (haveMove) break;
for (var nn=mm+1;nn < 10;nn++) {
if (haveMove) break;
if (Math.abs(shuffle[mm] – shuffle[nn]) == 1) {
haveMove = true;
break;}
} }
if (!haveMove) countNull++;
}
}
document.body.innerHTML+=” Number of null moves in 10000 games (50000 draws) ” + countNull + “rn”;
}
</script>
</head>

<body>
<h1>Spider Solitaire test</h1>
<input type=”button” value=”Run Again” onClick=”genform();”>
<br>
</body>
</html[/code]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@rootAug 13.2018 — Bad move.

Forms are fundamental part of HTML and web servers.

A form should be the frame that you build your scripting on so that if there is a problem, the form still works, its called redundancy or a fallback position where your application will function regardless ofg any scripting bugs or lack of support for scripting, thats one thing you have neglected to think about, there are millions of people that have browsers that either have no java script or it is just not supported in those browsers, this means that the viewer gets to see a blank screen.
Copy linkTweet thisAlerts:
@wbportauthorAug 13.2018 — I changed the last few lines of the page quoted above, it flies now. This is what the last lines of the script look like now:
for (var mm = 0;mm &lt; 9;mm++) {
if (haveMove) break;
for (var nn=mm+1;nn &lt; 10;nn++) {
if (haveMove) break;
if ((shuffle[nn] - shuffle[mm]) == 1) {
haveMove = true;
break;}
} }
if (!haveMove) countNull++;
}
}
document.tournform.outputField.value+=" Number of null moves in 10000 games (50000 draws) " + countNull + "rn";
}
&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;h1&gt;Spider Solitaire test&lt;/h1&gt;
&lt;form name="tournform"&gt;
&lt;input type="button" value="Run Again" onClick="genform();"&gt;&lt;br&gt;
&lt;textarea name="outputField" rows="35" cols="60"&gt;&lt;/textarea&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@a1seniorcareadvisorsAug 14.2018 — Structures are key piece of HTML and web servers.

A shape ought to be the edge that you manufacture your scripting on so that if there is an issue, the frame still works, its called repetition or a fallback position where your application will work in any case ofg any scripting bugs or absence of help for scripting, that is one thing you have fail to consider, there are a large number of individuals that have programs that either have no java content or it is simply not bolstered in those programs, this implies the watcher gets the chance to see a clear screen.

Note:- [url=https://www.a1seniorcareadvisors.com/]A1 Senior Care Advisors[/url] your local free senior living, Placement & Care Referral Services in washington dc With having over 20 years experience in Senior Living & Health Care.
×

Success!

Help @wbport 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.24,
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,
)...