/    Sign up×
Community /Pin to ProfileBookmark

Can you see a problem in this simple code?

I’m really sure that this should be working. Can you see why it doesn’t work?

[CODE]function showAnswers(){
var longAnswer = response[pointers[qnumber]];
//alert(longAnswer); displays 1,2,3,4,5,6,7
var shortAnswer = new Array();
shortAnswer = longAnswer.split(‘,’);
alert(shortAnswer[0]);

if($_(‘ques’).value!==”){
$_(‘resp’).value =response[pointers[qnumber]];
$_(‘resp’).focus();
}
}[/CODE]

Glen R
[URL=”http://a4jp.com/index-en.html”]http://a4jp.com/index-en.html[/URL]

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@KorMar 24.2011 — Incomplete information. What is [B]$_()[/B]? A referential custom function? In which JavaScript Framework? And, [I]what[/I] is not working?
Copy linkTweet thisAlerts:
@a4jp_comauthorMar 24.2011 — The full code is on this page:

http://agreatdream.com/quiz30test.html

The alert longAnswer works but [CODE]alert(shortAnswer[0]);[/CODE]
doesn't bring up an alert.

"ques" and "resp" are single line text fields.

[CODE]<input style="font-size: 1.8em; text-align: center" id="ques" value="" size="66" readonly />

<input style="font-size: 1.8em; text-align: center" id="resp" value="" size="66" onKeyPress="doClick(event)" />[/CODE]


It is okay if the $ info is cut.

[CODE]function showAnswers(){
var longAnswer = response[pointers[qnumber]];
//alert(longAnswer); displays 1,2,3,4,5,6,7
var shortAnswer = new Array();
shortAnswer = longAnswer.split(',');
alert(shortAnswer[0]);
}[/CODE]


Glen R

http://a4jp.com/index-en.html
Copy linkTweet thisAlerts:
@KorMar 24.2011 — Let me answer my question in your place ? I saw that $_() is a custom function, as I suspected:

<i>
</i>function $_(IDS) { return document.getElementById(IDS); }

Now:

alert(shortAnswer[0]) doesn't bring up an alert.
[/quote]

Try this:
<i>
</i>var longAnswer = response[pointers[qnumber]];
var shortAnswer = longAnswer.split(',');
alert(shortAnswer[0]);

There is no need to declare the variable shortAnswer as an array. the split() method will do that automatically.

But, one question: is it [B]longAnswer[/B] (and, of course, : [B]response[pointers[qnumber]][/B]) a string? Or an array?
Copy linkTweet thisAlerts:
@a4jp_comauthorMar 24.2011 — That kind of worked but I only got an alert for questions with one answer. Like in Hiragana 1. The alert for Medical English - The Hand, doesn't work.

I think the single answer questions are acting like strings but the multiple dimensional answers are in an array so they might need to be changed to work...

Sorry, I'm still a beginner in JavaScript.

Glen R

http://a4jp.com/index-en.html
Copy linkTweet thisAlerts:
@a4jp_comauthorMar 25.2011 — This is what one type of array looks like.

[CODE]var VersionMonthsEnR = [
['1','January','january-i---a4jp-com.gif'],
['2','February','february-i---a4jp-com.gif'],
['3','March','march-i---a4jp-com.gif']
];[/CODE]


And another one.

[CODE]var VersionBodyHand = [
[['palm','the palm'],'Name part A','medical-hand-i-a4jp.jpg',['palm.mp3','palm-.mp3'],'1','It's on the inner side of the hand, starting at the wrist and ending at the base of the fingers',['palm pain - te no hira no itami','palm side of a hand - te no hira no gawa']],
[['thumb','the thumb'],'Name part B','medical-hand-i-a4jp.jpg',['thumb.mp3','thumb-.mp3'],'1','It moves differently to the other 4 fingers. It is usually short and thick.'],
[['index finger','the index finger'],'Name part C','medical-hand-i-a4jp.jpg'],
[['middle finger','the middle finger'],'Name part D','medical-hand-i-a4jp.jpg'],
[['ring finger','the ring finger'],'Name part E','medical-hand-i-a4jp.jpg'],
[['baby finger','the baby finger','pinky','the pinky','little finger','the little finger'],'Name part F','medical-hand-i-a4jp.jpg'],
[['top of the finger','the top of the finger','tip of the finger','the tip of the finger'],'Name part G','medical-hand-i-a4jp.jpg'],
[['middle of the finger','the middle of the finger'],'Name part H','medical-hand-i-a4jp.jpg'],
[['base of the finger','the base of the finger'],'Name part I','medical-hand-i-a4jp.jpg']// No comma after last entry
];[/CODE]


The first array only has one answer and works with the code from before but the second has multiple answers and doesn't work.

Any ideas?

Glen R

http://a4jp.com/index-en.html
Copy linkTweet thisAlerts:
@a4jp_comauthorMar 25.2011 — How do I check if something is an array or string with alert?
Copy linkTweet thisAlerts:
@a4jp_comauthorMar 26.2011 — Mmmmm this is a bit trickier than I thought it would be...

Glen R

http://a4jp.com/index-en.html
×

Success!

Help @a4jp_com 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.19,
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,
)...