/    Sign up×
Community /Pin to ProfileBookmark

Help with script

Ok this is the code to a magic 8 ball

the problem I’m have is that I can’t figure a way to make an alert come up everytime the same question is repeated.

any ideas would be greatly appreciated

<script type=”text/javascript” language=”javascript”>

function Answerquestion()
{
var response = new Array ()
response [0] = “Maybe”;
response [1] = “Yes”;
response [2] = “No”;
response [3] = “Yes, definately”;
response [4] = “Reply is hazy, please try again”;
response [5] = “It appears to be so”;
response [6] = “What is it you really want to know?”;
response [7] = “Outlook is good”;
response [8] = “My sources say no”;
response [9] = “Cannot predict now”;
response [10] = “Don’t count on it”;
response [11] = “Signs point to yes”;
response [12] = “As I see it, yes”;
response [13] = “Concentrate and ask again”;
response [14] = “Better not tell you now”;

var x = Math.random()* response.length;
x = Math.floor(x);

var question = txtQuestion.value
var lastChar = question.charAt(question.length – 1)

if (lastChar == ‘?’)
{ Answer.innerHTML=(response[x])
}
else
alert(“Please ask a question that ends with a ‘?'”)
{
txtQuestion.focus()

}

var newquestion = “txtQuestion.value”;
var oldquestion = question

if (newquestion = oldquestion)
{
alert(“Question Cannot repeat”)
}

}

</script>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@pcx99Feb 21.2007 — 

var newquestion = txtQuestion.value;
var oldquestion = question

if (newquestion =[b]=[/b] oldquestion)
{
alert("Question Cannot repeat")
}


}

[/quote]


You forgot the second equal sign, one means assign (always true), two means check. I also took the quotes out from around txtQuestion.value.
Copy linkTweet thisAlerts:
@TyangauthorFeb 21.2007 — Thanks, alot...you are the MAN!!!
×

Success!

Help @Tyang 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.20,
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,
)...