/    Sign up×
Community /Pin to ProfileBookmark

Hey all!

I need to check 2 statements over and over again, but I have no clue how to make a loop out of it…

[CODE]
mp5s = leftovernet / 250;
pistols = 0;
totalguns = mp5s + pistols;

if (totalguns < document.gcform.gcthugs.value) {
mp5s = mp5s – 1;
pistols = pistols +5;
if (totalguns < document.gcform.gcthugs.value) {
mp5s = mp5s – 1;
pistols = pistols +5;
if (totalguns < document.gcform.gcthugs.value) {
mp5s = mp5s – 1;
pistols = pistols +5;
if (totalguns < document.gcform.gcthugs.value) {
mp5s = mp5s – 1;
pistols = pistols +5;
if (totalguns < document.gcform.gcthugs.value) {
mp5s = mp5s – 1;
pistols = pistols +5;

// AND THIS GOES ON FOREVER πŸ™

}
}
}
}
}

gcresultguns.firstChild.nodeValue = mp5s;
gcresultnet.firstChild.nodeValue = pistols;
[/CODE]

to post a comment
JavaScript

5 Comments(s) ↴

Copy linkTweet thisAlerts:
@KorApr 06.2005 β€”Β why not use a [b]while[/b] statement instead of an [b]if[/b] one ?
Copy linkTweet thisAlerts:
@Daedalus123authorApr 06.2005 β€”Β Thats what I want to do, but I can't get it to work. This is as good as I can make it, but it becomes infinite. Sorry if I was uncear about it.

[CODE]
if (document.gcform.gcradio[0].checked == true) {
var mp5s = leftovernet / 250;
var pistols = 0;
var totalguns = mp5s + pistols;
while (totalguns < document.gcform.gcthugs.value) {
mp5s = mp5s - 1;
pistols = pistols + 5;
}
gcresultguns.firstChild.nodeValue = mp5s;
gcresultnet.firstChild.nodeValue = pistols;
}
[/CODE]
Copy linkTweet thisAlerts:
@KorApr 06.2005 β€”Β try:

if (document.gcform.gcradio[0].checked == true) {

var mp5s = leftovernet / 250;

var pistols = 0;

var totalguns = mp5s + pistols;

while (totalguns < document.gcform.gcthugs.value) {

mp5s = mp5s - 1;

pistols = pistols + 5;

[color=red]totalguns = mp5s + pistols;[/color]

}

gcresultguns.firstChild.nodeValue = mp5s;

gcresultnet.firstChild.nodeValue = pistols;

}

if I well understood your intention
Copy linkTweet thisAlerts:
@Daedalus123authorApr 06.2005 β€”Β Thank you ? that was exactly what I wanted. I just feel a bit stupid 'cause it was something that easy lol.
Copy linkTweet thisAlerts:
@KorApr 06.2005 β€”Β Thank you ? that was exactly what I wanted. I just feel a bit stupid 'cause it was something that easy lol.[/QUOTE]

No problem. It happens to all of us here from time to time, I assure you ?
Γ—

Success!

Help @Daedalus123 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 5.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

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