From 0e63521ee0ea0041e76c132687b3d0c413ab9262 Mon Sep 17 00:00:00 2001 From: Michael Q Larson Date: Sat, 24 Jan 2015 23:03:25 -0800 Subject: [PATCH] refactor verbs, compliments and phrases into resources controller and require them where necessary. Create tutorial bonfire. Clean up existing bonfires. Fix minor ui issues. --- controllers/bonfire.js | 35 +++------------ controllers/challenges.js | 51 +++------------------ controllers/resources.json | 91 +++++++++++++++++++++++++++++++++++++- public/css/main.less | 1 + seed_data/bonfires.json | 40 ++++++++++++++--- seed_data/challenge-hashes | 1 - views/bonfire/show.jade | 11 +++-- views/challenges/show.jade | 2 +- 8 files changed, 144 insertions(+), 88 deletions(-) diff --git a/controllers/bonfire.js b/controllers/bonfire.js index d88a9d4c45..25dbcdab1b 100644 --- a/controllers/bonfire.js +++ b/controllers/bonfire.js @@ -1,7 +1,11 @@ var _ = require('lodash'), debug = require('debug')('freecc:cntr:bonfires'), Bonfire = require('./../models/Bonfire'), - User = require('./../models/User'); + User = require('./../models/User'), + resources = require('./resources.json'), + phrases = resources.phrases, + verbs = resources.verbs, + compliments = resources.compliments; /** * Bonfire controller @@ -24,33 +28,6 @@ exports.index = function(req, res) { exports.returnBonfire = function(req, res, next) { var bonfireNumber = parseInt(req.params.bonfireNumber) || 0; - var verbs = [ - 'ACED', - 'NAILED', - 'ROCKED', - 'SCORCHED', - 'DEVASTATED', - 'OWNED', - 'CRUSHED', - 'CONQUERED', - 'KILLED', - 'SHREDDED', - 'ANNIHILATED', - 'NUKED' - ]; - var phrases = [ - "Shout it from on top of a mountain", - "Tell everyone and their dogs", - "Show them. Show them all!", - "Inspire your friends", - "Tell the world of your greatness", - "Look accomplished on social media", - "Share news of your grand endeavor", - "Establish your alibi for the past two hours", - "Prove to mom that computers aren't just for games" - ]; - - // This code is in bad need of refactoring var bonfiresToFind = req.user.bonfiresHash; var bonfiresArray = _.map(bonfiresToFind, function(value, index) { @@ -86,6 +63,7 @@ exports.returnBonfire = function(req, res, next) { points: req.user ? req.user.points : undefined, verb: verbs[Math.floor(Math.random() * verbs.length)], phrase: phrases[Math.floor(Math.random() * phrases.length)], + compliments: compliments[Math.floor(Math.random() * phrases.length)], bonfires: bonfire, bonfireHash: bonfire[bonfireNumber]._id }); @@ -141,6 +119,7 @@ exports.returnIndividualBonfire = function(req, res, next) { points: req.user ? req.user.points : undefined, verb: verbs[Math.floor(Math.random() * verbs.length)], phrase: phrases[Math.floor(Math.random() * phrases.length)], + compliment: compliments[Math.floor(Math.random() * phrases.length)], bonfires: bonfire, bonfireHash: bonfire[bonfireNumber]._id }); diff --git a/controllers/challenges.js b/controllers/challenges.js index 9d3b325df6..401940ca29 100644 --- a/controllers/challenges.js +++ b/controllers/challenges.js @@ -4,56 +4,16 @@ */ var _ = require('lodash'), debug = require('debug')('freecc:cntr:challenges'), - Challenge = require('./../models/Challenge'); + Challenge = require('./../models/Challenge'), + resources = require('./resources.json'), + phrases = resources.phrases, + verbs = resources.verbs, + compliments = resources.compliments; var highestChallengeNumber = 53; exports.returnChallenge = function(req, res, next) { var challengeNumber = parseInt(req.params.challengeNumber) || 0; - var verbs = [ - 'ACED', - 'NAILED', - 'ROCKED', - 'SCORCHED', - 'DEVASTATED', - 'OWNED', - 'CRUSHED', - 'CONQUERED', - 'KILLED', - 'SHREDDED', - 'ANNIHILATED', - 'NUKED' - ]; - var compliments = [ - "You've got the power!", - "Nicely done!", - "Rock and roll!", - "High five!", - "Bravo!", - "Encore!", - "Challenge destroyed!", - "Power level 9000!", - "Most efficient!", - "Party on Wayne!", - "You've got the touch!", - "You're on fire!", - "Don't hurt 'em, Hammer!", - "The town is now red", - "To the nines!", - "Nothing but net!", - "Even grumpy cat is impressed" - ]; - var phrases = [ - "Shout it from on top of a mountain", - "Tell everyone and their dogs", - "Show them. Show them all!", - "Inspire your friends", - "Tell the world of your greatness", - "Look accomplished on social media", - "Share news of your grand endeavor", - "Establish your alibi for the past two hours", - "Prove to mom that computers aren't just for games" - ]; if (challengeNumber > highestChallengeNumber) { challengeNumber = 0; } Challenge.find({}, null, { sort: { challengeNumber: 1 } }, function(err, c) { if (err) { @@ -70,6 +30,7 @@ exports.returnChallenge = function(req, res, next) { cc: req.user ? req.user.challengesHash : undefined, points: req.user ? req.user.points : undefined, verb: verbs[Math.floor(Math.random() * verbs.length)], + compliment: compliments[Math.floor(Math.random() * compliments.length)], phrase: phrases[Math.floor(Math.random() * phrases.length)], challenges: c }); diff --git a/controllers/resources.json b/controllers/resources.json index 098f41fa46..adae5097a6 100644 --- a/controllers/resources.json +++ b/controllers/resources.json @@ -144,5 +144,94 @@ "You can complete CoderByte problems while you continue to work through Free Code Camp's challenges.", "Be sure to pair program on these challenges, and remember to apply the RSAP methodology.", "Click the button below to return to the Pair Programming challenge, then mark it complete." + ], + "verbs": [ + "aced", + "nailed", + "rocked", + "scorched", + "devastated", + "destroyed", + "owned", + "crushed", + "conquered", + "killed", + "shredded", + "annihilated", + "nuked", + "smashed", + "decimated", + "demolished", + "devoured", + "pulvarized", + "banished", + "throttled", + "blew away", + "roundhoused", + "tangoed", + "wrangled", + "shot down", + "scarfed", + "grappled", + "incinerated", + "uppercutted" + ], + "compliments": [ + "You've got the power!", + "Nicely done!", + "Rock and roll!", + "High five!", + "Bravo!", + "Encore!", + "Challenge destroyed!", + "Power level 9000!", + "Most efficient!", + "Party on, Wayne!", + "You've got the touch!", + "You're on fire!", + "Don't hurt 'em, Hammer!", + "The town is now red", + "To the nines!", + "Nothing but net!", + "Grumpy cat approves", + "The world rejoices", + "That's the way it's done!", + "You rock!", + "Woo-hoo!", + "We knew you could do it", + "Hyper Combo Finish!", + "Nothing but net!", + "Boom-shakalaka!", + "You're a shooting star!", + "You're unstoppable!", + "Way cool!", + "You're king of the world!", + "Walk on that sunshine!", + "Keep on trucking!", + "Off the charts!", + "There is no spoon", + "Cranked it up to 11!", + "Escape velocity reached!", + "You make this look easy!", + "Passed with flying colors!", + "One step closer...", + "You've got this!", + "Happy happy joy joy!", + "Tomorrow, the world!", + "Here's looking at you, Code!", + "It's alive. It's alive!" + ], + "phrases": [ + "Shout it from on top of a mountain", + "Tell everyone and their dogs", + "Show them. Show them all!", + "Inspire your friends", + "Tell the world of your greatness", + "Look accomplished on social media", + "Share news of your grand endeavor", + "Establish your alibi for the past two hours", + "Prove to mom that computers aren't just for games", + "With coding power comes sharing responsibility", + "Have you told your friends of your coding powers?" ] -} +} \ No newline at end of file diff --git a/public/css/main.less b/public/css/main.less index 2938ac72dd..bbf1a63c24 100644 --- a/public/css/main.less +++ b/public/css/main.less @@ -510,6 +510,7 @@ thead { text-align: center; margin-bottom: -30px; border-radius: 5px 5px 0px 0px; + padding-left: 50px; } .closing-x { diff --git a/seed_data/bonfires.json b/seed_data/bonfires.json index 0a5dedfe97..db847aecea 100644 --- a/seed_data/bonfires.json +++ b/seed_data/bonfires.json @@ -1,13 +1,33 @@ [ { - "_id" : "aaa48de84e1ecc7c742e1124", - "name": "Palindrome Tester", + "_id" : "7123c8c441eddfaeb5bdef0d", + "name": "Meet Bonfire", "difficulty": 1, "description": [ - "Your job is to determine if a provided string is a palindrome.", - "The definition of a palindrome can be found at http://en.wikipedia.org/wiki/Palindrome.", - "Strings will be passed in with varying formats, such as \"racecar\", \"RaceCar\", and \"race CAR\" among others.", - "Return true if the string is a palindrome, otherwise false" + "Click the button below for further instructions.", + "Your goal is to fix the failing test.", + "First, run all the tests by clickin \"Run code\" or by pressing Control + Enter", + "The failing test is in red. Fix the code so that all tests pass. Then you can move on to the next Bonfire." + ], + "tests": [ + "expect(meetBonfire(\"test\")).to.be.a(\"boolean\");", + "expect(meetBonfire(\"test\")).to.be.true;" + ], + "challengeSeed": "function meetBonfire(argument) {\n // Good luck!\n console.log(\"you can read this function's argument in the developer tools\", argument);\n\nreturn false;\n}\n\n", + "challengeEntryPoint": "meetBonfire(\"You can do this!\");", + "bonfireNumber": 0, + "challengeEntryPointNegate" : "meetBonfire(\"You can do this!\");" + }, + { + "_id" : "aaa48de84e1ecc7c742e1124", + "name": "Check for Palindromes", + "difficulty": 1, + "description": [ + "Return 'true' if a given string is a palindrome.", + "A palindrome is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation and case.", + "You'll need to remove punctuation and turn everything lower case in order to check for palindromes.", + "We'll pass strings with varying formats, such as \"racecar\", \"RaceCar\", and \"race CAR\" among others.", + "Return true if the string is a palindrome. Otherwise, return false." ], "tests": [ "expect(palindrome(\"eye\")).to.be.a(\"boolean\");", @@ -28,12 +48,20 @@ "name": "Validate US Telephone Numbers", "difficulty": 3, "description": [ + "Return true if the passed string is a valid US phone number", "The user may fill out the form field any way they choose as long as it is a valid US number. The following are all valid formats for US numbers:", "555-555-5555, (555)555-5555, (555) 555-5555, 555 555 5555, 5555555555, 1 555 555 5555", "For this challenge you will be presented with a string such as \"800-692-7753\" or \"8oo-six427676;laskdjf\". Your job is to validate or reject the US phone number based on any combination of the formats provided above. The area code is required. If the country code code is provided, you must confirm that the country code is \"1\". Return true if the string is a valid US phone number; otherwise false." ], "tests": [ "expect(telephoneCheck(\"555-555-5555\")).to.be.a(\"boolean\");", + "assert.deepEqual(telephoneCheck(\"1 555-555-5555\"), true);", + "assert.deepEqual(telephoneCheck(\"1 (555) 555-5555\"), true);", + "assert.deepEqual(telephoneCheck(\"5555555555\"), true);", + "assert.deepEqual(telephoneCheck(\"555-555-5555\"), true);", + "assert.deepEqual(telephoneCheck(\"(555)555-5555\"), true);", + "assert.deepEqual(telephoneCheck(\"1(555)555-5555\"), true);", + "assert.deepEqual(telephoneCheck(\"1 555 555 5555\"), true);", "assert.deepEqual(telephoneCheck(\"555-555-5555\"), true);", "assert.deepEqual(telephoneCheck(\"1 456 789 4444\"), true);", "assert.deepEqual(telephoneCheck(\"123**&!!asdf#\"), false);", diff --git a/seed_data/challenge-hashes b/seed_data/challenge-hashes index a03c038d90..ca100cb520 100644 --- a/seed_data/challenge-hashes +++ b/seed_data/challenge-hashes @@ -1,7 +1,6 @@ /* -"7123c8c441eddfaeb5bdef0d" "c3a4d278b9e760a0ffe8321f" "aceca143b92049a4392a859e" "ce9394f67d413734758e27e4" diff --git a/views/bonfire/show.jade b/views/bonfire/show.jade index eaa1c21170..88d28655b9 100644 --- a/views/bonfire/show.jade +++ b/views/bonfire/show.jade @@ -67,7 +67,7 @@ block content #complete-bonfire-dialog.modal(tabindex='-1') .modal-dialog.animated.zoomIn.fast-animation .modal-content - .modal-header.challenge-list-header Nicely done! + .modal-header.challenge-list-header= compliment a.close.closing-x(href='#', data-dismiss='modal', aria-hidden='true') × .modal-body(ng-controller="pairedWithController") @@ -77,13 +77,12 @@ block content - if (cc) form.form-horizontal(novalidate='novalidate', name='completedWithForm') .form-group.text-center - label(for="existingUserName") If you paired with someone, enter their username here. .col-xs-10.col-xs-offset-1.col-sm-8.col-sm-offset-2.col-md-8.col-md-offset-2 - .input-group.twitter-input + .input-group.twitter-input.animated.fadeIn // extra field to distract password tools like lastpass from injecting css into our username field input.form-control(ng-show="false") span.input-group-addon @ - input.form-control#completed-with(name="existingUser", placeholder='Otherwise just leave it blank', existing-username='', ng-model="existingUser", autofocus) + input.form-control#completed-with(name="existingUser", placeholder="If you paired, enter your pair's username here", existing-username='', ng-model="existingUser", autofocus) .col-xs-10.col-xs-offset-1.col-sm-8.col-sm-offset-2.col-md-8.col-md-offset-2(ng-show="completedWithForm.$error.exists && !completedWithForm.existingUser.$pristine && existingUser.length > 0") alert(type='danger') span.ion-close-circled @@ -94,8 +93,8 @@ block content - if (points && points > 2) a.animated.fadeIn.btn.btn-lg.btn-block.btn-twitter(href="https://twitter.com/intent/tweet?text=I%20just%20#{verb}%20%40FreeCodeCamp%20Challenge%20%23#{number}:%20#{name}&url=http%3A%2F%2Ffreecodecamp.com/bonfires/#{number}&hashtags=learntocode, javascript" target="_blank") - i.fa.fa-twitter   - = phrase + i.fa.fa-twitter   + = phrase - else a.animated.fadeIn.btn.btn-lg.signup-btn.btn-block(href='/login') Sign in so you can save your progress #all-bonfires-dialog.modal(tabindex='-1') diff --git a/views/challenges/show.jade b/views/challenges/show.jade index 3111eb1edd..ddb2fa6dce 100644 --- a/views/challenges/show.jade +++ b/views/challenges/show.jade @@ -19,7 +19,7 @@ block content #complete-challenge-dialog.modal(tabindex='-1') .modal-dialog.animated.zoomIn.fast-animation .modal-content - .modal-header.challenge-list-header Nicely done! + .modal-header.challenge-list-header= compliment a.close.closing-x(href='#', data-dismiss='modal', aria-hidden='true') × .modal-body .text-center