/    Sign up×
Community /Pin to ProfileBookmark

I’d like to emulate the intelligence tests at this site:
[url]http://intelligence-test.net/part1/[/url]
You have to spell the answers exactly right, then, when you do, the field turns green, locks out further input and automatically updates the score at the bottom of the page.

Very clever – and the tests are very good – worth spending time on.

As I’m just a beginner, can anyone point me to code that does this stuff so I can try customizing my own version, and hopefully learn more js as I go along? Many thanks!

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@jamJun 08.2009 — Hey, this depends how much of a beginner you are? Because this is a very bespoke script, it's easily mimicable but i'm not going to post a pageload of code up here if it's of no benefit to you... On a basic level you can right-click and view-source the page to see how it works... The main script code is: http://intelligence-test.net/part1/script2.js and you can see each of the parts of the script doing what you've described in sequence. The handler for the input is:
<i>
</i>onKeyUp="javascript: checkQ('q3')"


So it all runs through the main function "checkQ"...

The script also hashes the answers so they can't just be broken by looking at them...

It's basically a mashup of these few concepts:

It's a [url="http://javascript.internet.com/miscellaneous/basic-javascript-quiz.html"]basic quiz[/url], which rather than clicking the "check answers" checks the answer every time you [url="http://www.w3schools.com/jsref/jsref_onkeyup.asp"]press a key[/url], and then [url="http://www.codetoad.com/javascript/enable_disable_form_element.asp"]disables the input box[/url] if they're correct.

Cheers,

Jamey
Copy linkTweet thisAlerts:
@martinlaauthorJun 08.2009 — Jamey - many thanks! Very helpful.
Copy linkTweet thisAlerts:
@jamJun 08.2009 — Cheers =] glad to be of help.
Copy linkTweet thisAlerts:
@martinlaauthorJun 08.2009 — Ah - I guess I should have looked at the js code first. I'm such a beginner that I don't understand the encoding where the 33 questions reside - at the top of the page. Are these alphanumeric characters encoded as hex or something?
Copy linkTweet thisAlerts:
@jamJun 08.2009 — It's hashing, an sha1 hash to be precise...

Basically, the way this quiz checks that the answer is correct is:

- Convert the input string to uppercase

- Hash the string using SHA1 algorithm

- Compare that hash with the pre-defined answers hash (the q[n] = 'hex string' bit)

- If both are the same, the answer is correct.

Basically because the hash is a unique representation of the answer string, which can't be reversed...

So the code:
<i>
</i>function checkQ(str) {
if(sha1Hash(document.getElementById(str).value.toUpperCase()) == q[str])
{
validate1(str);
}
else
{
validate2(str);
}


Could be changed to:
<i>
</i>function checkQ(str) {
if(document.getElementById(str).value.toUpperCase() == q[str])
{
validate1(str);
}
else
{
validate2(str);
}

(and then the array changed to: )
<i>
</i>q['q1'] = '26 LETTERS OF THE ALPHABET';
q['q2'] = '7 DAYS OF THE WEEK';
//and so on


If you did not want that added security (that's just to demonstrate the functionality btw, the added security makes sence)...

Cheers,

Jamey
Copy linkTweet thisAlerts:
@martinlaauthorJun 08.2009 — SHA-! - thanks Jamey. You've expanded my horizons no end! ?

I checked and indeed it works the exact way you describe.
Copy linkTweet thisAlerts:
@jamJun 08.2009 — Haha =] Glad to be of help.

Cheers,

Jamey
×

Success!

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