Skip to content

Instantly share code, notes, and snippets.

@jmealo
Last active February 3, 2017 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmealo/d3065e6eb2735188808a1a699783059f to your computer and use it in GitHub Desktop.
Save jmealo/d3065e6eb2735188808a1a699783059f to your computer and use it in GitHub Desktop.
Pasting this into the JavaScript console will grade your AQ on Wired: https://www.wired.com/2001/12/aqtest/
// This is an attempt at doing things the most obvious way with an
// emphasis on readability ... It's not clever but it's still not obvious
// what we're doing. It also requires you to know both javascript and
// CSS selectors
var addIfAgreed = [
2, 4, 5, 6, 7, 9, 12, 13, 16, 18, 19, 20, 21, 22, 23, 26, 33, 35, 39, 41,
42, 43, 45, 46
]
var addIfDisagreed = [
1, 3, 8, 10, 11, 14, 15, 17, 24, 25, 27, 28, 29, 30, 31, 32, 34, 36, 37,
38, 40, 44, 47, 48, 49, 50
]
function countMatchingArrayItems (arr1, arr2) {
return arr1.filter(function (item) {
return arr2.indexOf(item) !== -1
}).length
}
function selectorToAnswerNumbers (selector) {
var nodeList = document.querySelectorAll(selector),
elementArray = Array.prototype.slice.call(nodeList)
return elementArray.map(function (element) {
return parseInt(element.name.replace('answer_', ''), 10)
}) || []
}
function scoreTest () {
var disagreed = selectorToAnswerNumbers('[name*=answer_][value*=d]:checked')
var agreed = selectorToAnswerNumbers('[name*=answer_][value*=a]:checked')
var score = countMatchingArrayItems(agreed, addIfAgreed)
score = score + countMatchingArrayItems(disagreed, addIfDisagreed)
return score
}
alert(scoreTest())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment