Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit e8a5af89568c4130999adda28de6683fe8c0af5c @coolaj86 committed Jul 1, 2012
Showing with 1,683 additions and 0 deletions.
  1. +18 −0 README.md
  2. +107 −0 color-code.js
  3. +317 −0 color-code.json
  4. +23 −0 package.json
  5. +1,178 −0 quiz_radio.xml
  6. +40 −0 tally.js
@@ -0,0 +1,18 @@
+The Color Code
+===
+
+This is a simple commandline questionaire that asks the questions from The Color Code in random order and the answers also randomized.
+
+The is particularly useful for people like myself who have pre-conceived notions about their personality and want to take the test in a less-biased fashion.
+
+ npm install -g color-code
+ color-code
+
+Upon completion of the test, the results are saved in a JSON file (the path to which is printed to the screen).
+
+Warning
+===
+
+I nabbed the questions from http://www.mhhe.com/business/management/buildyourmanagementskills/updated_flash/topic5d/quiz_radio.xml which I found in a google search, and without permission of the author.
+
+Enough people have created online versions of this test that I hope this not to be an issue.
@@ -0,0 +1,107 @@
+/*jshint strict:true node:true es5:true onevar:true laxcomma:true laxbreak:true eqeqeq:true immed:true latedef:true*/
+(function () {
+ "use strict";
+
+ var fs = require('fs')
+ , questionsRaw = require('./color-code.json')
+ , total = questionsRaw.length
+ , questions = []
+ , colors = ['red', 'blue', 'white', 'yellow']
+ , current
+ , responses = {
+ totals: {
+ red: 0
+ , blue: 0
+ , white: 0
+ , yellow: 0
+ }
+ , answers: {
+ }
+ }
+ ;
+
+ function shuffle() {
+ return Math.random() - 0.5;
+ }
+
+ questionsRaw.forEach(function (q, i) {
+ questions.push({
+ number: i
+ , question: q[0]
+ , red: q[1]
+ , blue: q[2]
+ , white: q[3]
+ , yellow: q[4]
+ });
+ });
+
+ function presentQuestion() {
+ var curNum = '#' + ((total - questions.length) + 1) + 'of ' + total + '\n'
+ ;
+
+ current = questions.pop();
+ if (current.question) {
+ console.log(curNum, current.question);
+ } else {
+ console.log(curNum, "Which described you best as a child?");
+ }
+ colors.sort(shuffle);
+ colors.forEach(function (color, i) {
+ console.log((i+1) + ')', current[color]);
+ });
+ console.log('');
+
+ if (questions.length) {
+ return true;
+ }
+ }
+
+ function saveResponses() {
+ var filename = 'color-code-test-' + Date.now() + '.json'
+ ;
+
+ // TODO output as YAML
+ fs.writeFile('color-code-test-' + Date.now() + '.json', JSON.stringify(responses, null, ' '), function (err) {
+ console.log('You finished');
+ console.log('red:', responses.totals.red);
+ console.log('blue:', responses.totals.blue);
+ console.log('white:', responses.totals.white);
+ console.log('yellow:', responses.totals.yellow);
+ console.log("Now go read the book to learn more!");
+ if (err) {
+ console.error("couldn't save results");
+ } else {
+ console.log(process.cwd() + '/' + filename);
+ }
+ process.stdin.pause();
+ });
+ }
+
+ questions.sort(shuffle);
+
+ process.stdin.resume();
+ process.stdin.setEncoding('utf8');
+
+ presentQuestion();
+ process.stdin.on('data', function (chunk) {
+ chunk = chunk.replace(/\s/gm, '');
+ var color = colors[chunk - 1]
+ ;
+
+ if (color) {
+ responses.answers[current.number] = color;
+ responses.totals[color] += 1;
+ } else {
+ console.log("Sorry, I didn't understand you. Respond again with 1, 2, 3, or 4");
+ return;
+ }
+ console.log('');
+
+ if (presentQuestion()) {
+ return;
+ }
+
+ saveResponses();
+ });
+
+}());
Oops, something went wrong.

0 comments on commit e8a5af8

Please sign in to comment.