/    Sign up×
Community /Pin to ProfileBookmark

Calling a local variable, possible?

From what I understand, this is not possible. Is there a workaround for it though?

For example this does not work:

[code=php]function Start(){
var name = window.prompt(“Please enter your player name:”, “unnamed”);
}

function Stop(){
endofgame.innerText = name +”, your total score is:” + points;
}[/code]

So say I have two buttons: Start and Stop. When a user clicks start, I want it to ask for their name. When they click stop, I want it to list their name along with some additional information.

What can I do?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51May 02.2005 — Why don;t you make it global?

<i>
</i>var name = "";
function Start(){
name = window.prompt("Please enter your player name:", "unnamed");
}

function Stop(){
endofgame.innerText = name +", your total score is:" + points;
}


Eric
Copy linkTweet thisAlerts:
@nsxauthorMay 02.2005 — Oh, well I don't want it to prompt them before the page loads. If I made it global, how could I tell it when to load?

Edit: Oh, I see your code now. Man I am so dumb. Thanks.
Copy linkTweet thisAlerts:
@A1ien51May 02.2005 — Then do not prompt it until you are ready. Just because it is global does not mean you need to give it the value right away. You can put the value in it at any time you want.

Eric
×

Success!

Help @nsx 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.29,
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,
)...