## Codecademy Walkthrough – Blackjack Challenge #1

Its the start of a new week and a new challenge on Codecademy… and quite literally a new challenge. I logged on to Codecademy this morning to find a new Courses page layout with lessons and projects grouped into sections and something called the Blackjack Challenge. Today’s Codecademy Walkthrough steps us through the first part of the Blackjack challenge: “Deal ’em Up”

Apart from a few layout changes and improvements, the first thing to notice with the exercise screen is that the script and console section have had a bit of a revamp. There is now some client side validation of code which is helpful to prevent mistakes and to give you better feedback if something isn’t quite right with your code. This week I don’t think I made a single syntax error due to this improved feedback mechanism. Nice work guys! OK, on with the lesson.

Blackjack challenge: Deal ’em Up >> Section 1 Before we get started….
Exercise 1. Introduction
Instead of the usual “hit run when you’re ready” we have a to do a bit of thinking with this introductory exercise. Now we have to actually return the text “I’m ready to build a blackjack game” in the console.

console.log(“I’m ready to build a blackjack game!”);

Exercise 2. Dealing
Now we have to refer back to the previous Dice Game project to lift the code used to generate random numbers. There’s a tweak needed though as instead of returning a random number from 1 to 6 we need to return a number from 1 to 10.

var randomRating = Math.floor(Math.random()*10 + 1);

Exercise 3. More Dealing
Next we need to build a function that takes two random scores from 1 to 10 and sums them together. There are no parameters in the function, but when returning the function don’t forget to include the empty brackets.

var twoRandomScores = function () {
var score1 = Math.floor(Math.random()*10 + 1);
var score2 = Math.floor(Math.random()*10 + 1);
return score1 + score2;
};
twoRandomScores();

Exercise 4. Give me my cards!
This exercise introduces concatenating a numeric value with a string to provide a sensible message by reintroducing the “string + variable concept.

var randomScore = Math.floor(Math.random()*52 + 1);
console.log(“I got the score “+randomScore);

Exercise 5. Scoring System
The modulo operator is reintroduced to provide the mechanism to convert a random number from 1 to 52 into a face value of a card by dividing by 13 and returning the remainder.

var deal = Math.floor(Math.random()*52 + 1);
var final = deal % 13;
console.log(final);

Exercise 6. Scoring System Continued
The modulo operator is continued in this exercise to return whether a random number is odd or even. Remember to use the triple equal signs here as we are comparing the modulo result with zero. The exercise hint talks about using the OR operator, but I didn’t use it or need it for this exercise. Here’s my code.

var outcome;
var randomScore = Math.floor(Math.random()*40 + 1);
if (randomScore % 2 === 0){
outcome = “even”;
} else {
outcome = “odd”;
}
console.log(outcome);

Exercise 7. We think you’re ready
Following on from the first exercise there is a brief review and what would have previously required us to hit the run button now asks us to confirm we are ready in code using the confirm command.

And that’s the first part of the Blackjack challenge done. The lessons, projects, and challenges are coming thick and fast now, and if like me you are noticing an improvement in your coding ability and combined with the enhancements to the  Codecademy website you will be rattling through the exercises at a good pace. I will attempt to get the next part of the challenge posted as a walkthrough later this week. In the meantime why don’t you take a look at my previous walkthroughs and see if you can make a more elegant version of my code.
Have fun!

Author: Paul Saunders

## iPad App Spotted in the Wild

Recently we were asked to develop a bespoke data acquisition iPad app for UK based airline Thomas Cook. They wanted an iPad app to replace some of their paper forms they used on board the aircraft to capture safety occurrences. The first version of the app was completed just before Christmas and is now being deployed to the pilot’s devices. During a visit to the customer’s site for another project we spotted evidence of our app in use. This poster is being put up in crew rooms:

It is always great to see a client driving adoption of enterprise software!

Author: Paul Saunders

## [VIDEO] YBoard Demo

I made a demonstration video for our new app YBoard for iPad. Sorry for the appalling production quality but it was filmed on my iPhone in our office and cobbled together using iMovie on the same iPad featured in the video. Its my first ever attempt at video editing and the music is a little cheesy I’m afraid.

Hope you like it. Please let us know what you think of a YBoard if you are already using it. We’ve had some positive feedback so far and Marcin is busy working on a new version which features multiple boards. We’re calling the concept “rooms” and we’re very pleased with the design. The only problem is that there is an awful lot of re-factoring required. Should be good for release in a few weeks time with a bit of luck.

Author: Paul Saunders

## Simplicity Sells: Apple vs HP

This week saw the staggering news regarding Apple’s financial performance for Q1 of their financial year whilst at the same time I was implementing Highrise and Backpack by 37Signals as internal management and organisation tools. This got me thinking (again) about simplicity.

Although I accept that simple software isn’t necessarily appropriate for everybody and for all use cases, it is certainly true that there is a requirement to consumerise business software and applications. The tools I have been implementing by 37Signals are definitely business tools – they have no relevance for use in the home, but they are highly consumerised, simple to use, easy to adopt and are instantly useful with very little setup time required. Apple have been as successful as they have thanks mainly to focussing on the needs of the consumer. This success has driven the trend for consumerisation of the business world.

Here’s a screenshot from Apple’s website – its the page you reach when you want to buy a laptop. It’s simple clean and easy to use:

Compare this to the the equivalent webpage by HP.

HP have struggled in the consumer market. Judging by the comparison in marketing style alone is it any wonder why Apple have succeeded whilst HP have not?

Author: Paul Saunders

## Codecademy Walkthrough – Starting a Startup

This week there are three exercises to tackle on Codecademy’s Code Year course. The first one is an app development exercise which follows on from the previous lessons about functions. Here’s my Walkthrough for the “Starting a Startup” lesson.

Exercise 1. Introduction
No code required here. Just hit ‘run’ to proceed

Exercise 2. What is fixed?
We’re now asked to begin the exercise by stating a variable for the fixed costs.

// Declare a variable fixedCosts
// and initialize it to 5000
var fixedCosts = 5000

Exercise 3. Define a function
There’s a slight change to the instruction text this week. The exercise objectives are much more clearly defined and bullet-pointed. Also the exercise pre-configured scripts are gone. You are forced to either build everything from scratch. (or copy and paste from the previous exercise). In my case I forced myself to rewrite all of my code to help the correct syntax become more instinctive. Now we’re wrapping the previous exercise’s fixedCost variable in a function.

// Define a function named calculateTotalCosts
// declare a variable fixedCosts the value of 5000
// have the function return fixedCosts
var calculateTotalCosts=function(){
var fixedCosts = 5000;
return fixedCosts;
};

Exercise 4. Show me the money!

Now we are asked to include a couple of arguments to the function and use them in a new variable to calculate variable costs.

//Define the function with two parameters
//Declare the variables fixedCosts and variableCosts
var calculateTotalCosts = function(salary, numWorkers){
var fixedCosts = 5000;
var variableCosts = salary * numWorkers;
return fixedCosts + variableCosts;
};
calculateTotalCosts(25000,5);

Exercise 5. Location, Location
Now we need to add an extra argument and if statement to factor in the additional cost of living in New York.

//Start by defining the function. It now has three parameters!
var calculateTotalCosts = function(salary, numWorkers, city) {
var fixedCosts = 5000;
var variableCosts = salary * numWorkers;
if (city === “NYC”) {
return fixedCosts + variableCosts + 30000
};
return fixedCosts + variableCosts
};
calculateTotalCosts(30000,7,”NYC”);

Exercise 6. Cheaper Options?

This exercise asks you to include an additional else if clause into the calculation. I struggled a little bit here to get the right syntax of where to put brackets and semi-colons, but got there in the end. One thing that didn’t help me was the fact that the area to type lesson code is a little bit small. You can only see 13 lines of code at once so it took me a while to debug and compare my script. I found the Scratch Pad to be useful for this exercise.

//Start by defining the function.
var calculateTotalCosts = function(salary, numWorkers, city) {
var fixedCosts = 5000;
var variableCosts = salary * numWorkers;

if (city === “NYC”) {
return fixedCosts + variableCosts + 30000;
}
else if (city === “BEJ”) {
return fixedCosts + variableCosts + 25000;
}
else {
return fixedCosts + variableCosts + 10000;
};
};
calculateTotalCosts(40000,3,””);

Exercise 7. Try it Out!
Finally you use the app for real to compare costs in various cities. Remember to declare the argument values in inverted commas as they are text strings.

var calculateTotalCosts = function(salary, numWorkers, city) {
var fixedCosts = 5000;
var variableCosts = salary * numWorkers;

if (city === “NYC”) {
return fixedCosts + variableCosts + 30000;
}
else if (city === “BEJ”) {
return fixedCosts + variableCosts + 25000;
}
else {
return fixedCosts + variableCosts + 10000;
};
};

console.log(calculateTotalCosts(50000,9,”NYC”));
console.log(calculateTotalCosts(50000,9,”BEJ”));
console.log(calculateTotalCosts(50000,9,”MUM”));

So how did I find this lesson?
Pretty good! I rattled through the exercises quickly with relatively few mistakes, so I must be learning something. There have been a number of improvements this week as I mentioned with lesson instructions and the way you are encouraged to duplicate your code. This lesson was pretty well structured with evenly balanced steps between exercises. It’s great to see the Codeacademy guys are continually moving things forward and are actively engaging with users via Twitter seeking user feedback. More of the same please Codecademy! I’m looking forward to the rest of this week’s lessons.

Previous Walkthroughs:
Codecademy Walkthrough – Hello New York

Author: Paul Saunders

## Codecademy Walkthrough – Hello New York

Last week I posted a blog which provided the answers in the form of a walkthrough of Codecademy’s applied Code Year lesson titled FizzBuzz. This proved to be a bit of a hit in the codecademy community. I got several tweets from grateful followers, plenty of comments on the blog and even a couple of tweets from @codecademy themselves encouraging me to keep up the walkthroughs. We’ve had hundreds of hits to the webite and are on page one of Google for all kinds of related searches for Codecademy answers.

The Codecademy site itself has seen several improvements this week, not least the addition of a Stack Exchange type Q&A forum. Due to the unprecedented encouragement, not least from Codecademy themselves I think there’s still room for a semi-regular walkthrough feature here if time allows. By popular demand here is a walkthrough of the “Hello, New York” applied Course from the second week of Code Year:

Exercise 1. Hailing a Taxi
The first exercise eases you in gently. All you have to do is declare the variable baseFare setting the value at 2.50. Remember that because the variable is a numeric value, not a string you don’t use “inverted commas”.
// Declare a variable named `baseFare` and assign
// it a value of `2.50`.
var baseFare = 2.50

Exercise 2. Make it Functional
Here we are given the basis of the taxiFare function and asked to return the baseFare value. We simply add “return baseFare” inside the braces. Easy enough
// remember to move baseFare inside the function taxiFare
// to properly scope the variable
var baseFare = 2.50;

// modify taxiFare to return the variable baseFare;
var taxiFare = function () {
return baseFare
};

Exercise 3. Where To?
The wording of this exercise confused me a little and it took me a while to figure out what I was being asked to do. Ignoring the lesson text and reading only the comments in the script helped me figure out exactly what was required. It turned out to be simpler than I first thought.  There does seem to be a slight bug with the Codecademy console. If you have failed several times to successfully run your script the result will sometimes still return an error even if you have the answer spot-on. However if you reset to the default code and try again it works just fine.
// add a parameter called milesTraveled to the function
// taxiFare
var taxiFare = function (milesTraveled) {
var baseFare = 2.50;
var costPerMile = 2.00;

// calculate cost using baseFare, milesTraveled, and
// costPerMile
var cost = baseFare + (milesTraveled * costPerMile);

return cost;
};

Exercise 4. After Dark

This is probably the hardest exercise of the lesson, simply because you have more code to write than any other exercise and there are a couple of typos in the exercise instructions. When it tells you that you need to include time before 6pm, it actually should read 6am. Again the code comments are more helpful than the exercise text….
// add a parameter called hourOfDay to the function
var taxiFare = function (milesTraveled, hourOfDay) {
var baseFare = 2.50;
var costPerMile = 2.00;
var nightSurcharge = 0.50; // 8pm to 6am, every night

var cost = baseFare + (costPerMile * milesTraveled);

// add the nightSurcharge to the cost starting at
// 8pm (20) or if it is before 6am (6)
if(hourOfDay >= 20 || hourOfDay < 6){
return cost + nightSurcharge;
}else {
return cost;
};
};

Exercise 5. You’ve arrived at your destination
Now all you need to do is apply the required values for milesTraveled and hourOfDay parameters. Curious the hourOfDay parameter has magically changed to pickupTime, but this doesn’t have any bearing. The only change required is to line 3
// use taxiFare to set tripCost to the cost of your
// ride covering 5 miles at 2 am in the morning
var tripCost = taxiFare(5,2);

// calculates taxi fare based upon miles traveled
// and the hour of the day in military time (0-23).
var taxiFare = function (milesTraveled, pickupTime) {
var baseFare = 2.50;
var costPerMile = 2.00;
var nightSurcharge = 0.50; // 8pm to 6am, every night

var cost = baseFare + (costPerMile * milesTraveled);

// add the nightSurcharge to the cost if it is after
// 8pm or before 6am
if (pickupTime >= 20 || pickupTime <= 6) {
cost += nightSurcharge;
}

return cost;
};

I hope that helps. I’ll ask our dev team to offer any code improvements they can think of. We had fun discussing that internally this week and maybe that’s a topic for future blog posts. More Codecademy Walkthroughs next week. Happy coding!

Author: Paul Saunders

## The Thinking Behind YBoard

Last week we launched our latest app YBoard for iPad on the iTunes App Store. It’s a sticky notes app and is our first attempt at an app which is intended for the general app market. All of our previous apps have either been bespoke enterprise app or targeted to a very specific use case. YBoard is completely different: Not only is it aimed at a much wider market, we simply do not know whether it is primarily a productivity app or whether it is a more fun or artistic app. Hopefully time will tell.

We have been thinking about developing general apps for quite a while now. We’ve discussed a number of ideas and have an open thread of ideas and suggestions on our internal message board. Everything from a Pregnancy Diary Logging app to a Brian Blessed Swearing Soundboard have been discussed and ultimately were all either ruled out or shelved. Usually this has been down to the fact that there are very few brand new ideas. Almost certainly when it comes to the iTunes App Store someone will have already beaten you to the drop or in the case of the “Automated Airplane Mode” app which we got quite excited about a couple of months ago are simply not possible to get approved by Apple. There’s nothing new about a sticky notes app. In fact there are already dozens of similar apps on the app store and some have been around for quite a long time. We’re not afraid of a competition, but what YBoard offers is ultimately targeting a different market and meeting some of the challenges in a different way. Perhaps this can be explained by describing how the idea for YBoard came about.

Last year there was an article in the New York Times which described the merger of two airlines Delta and Northwest. This article contained a now infamous photo of the draft project plan to merge the two airline’s operations, systems, branding and identity.

This massive project was planned using sticky notes. We were amazed by this, but equally not surprised. There are some pretty sophisticated software tools that would have been very helpful here, but sometimes old habits die hard. We use a combination of white boards, MS Project, Basecamp and FogBugz for planning and executing projects and there are many other brainstorming, mind mapping and project planning applications on the market. Who knows why such a low tech solution was used here, but maybe this indicated a requirement for some software that applied the same simplicity and user experience of putting sticky notes on a vast wall. This idea got our creative juices flowing and a list of functional requirements began to take shape.

At Conduce Software we have a policy that we call “Friday Afternoon Play” – Dan Pink calls these “Fedex days” in his book Drive (because you have to deliver something). On a Friday afternoon our development team are allowed to work on anything they like. Some will use the time for R&D or to try out new ideas, whilst others will use it for training, but there is no mandate to use the time productively on current projects. One of our guys, Marcin decided he was going to work on our sticky notes app idea. After only a couple of sessions working on the app Marcin had a working Alpha to show me. This first version of the app didn’t do anything exciting: sticky notes could be added and moved around… that was it. You can see what this version looked like on a previous blog post:
Testing Software is Child’s Play

After several weeks of working on the app solely on Friday afternoons and in our spare time Marcin and I had decided on what features absolutely had to be included in the first version of YBoard (as we had now begun to call our project.) Christmas was approaching and we had a window in our development schedule so I gave Marcin the green light to work on the app full time for two weeks in order to bring it to market. We had decided very early on that we wanted to use a very minimal and gesture based user interface for YBoard. This became more of a challenge as more features were added, but once the character of YBoard began to take form often an answer to a user interface challenge tended to become obvious. As we have done in the past the answer would probably lie with users. Several times I gave the app to friends, family members or staff and asked them to carry out a specific function in the app without telling them how to do it and certainly without telling them that the function I wanted them to test didn’t exist…. Their intuitive response often became the solution to the problem.

We submitted YBoard to the app store in the first week of January and almost exactly a week later it was approved by Apple and was ready for sale. Sales haven’t yet set the world alight, but then again we weren’t expecting them to at this early stage. It is a work in progress. There are a couple of essential features clearly missing from YBoard: For example you cannot yet open multiple boards and there are none of the collaboration features that we have planned in place yet, but we made the call to get something out there in the wild as soon as possible. YBoard is one of dozens of sticky notes apps and is probably the least feature rich of them all at this moment in time, but feedback from early adopters has been really positive. No other app of its kind has a look and feel quite like YBoard and we’re confident that as the feature list grows we can maintain the minimal, gesture based and intuitive user interface. We’ve also moved YBoard back onto the list of projects to be tackled as part of Friday Afternoon Play. This means that it will take us a bit longer to get new versions released, but you can be assured that all future development will have been done by someone who has chosen to work on it. YBoard is an example of what happens when you allow developers to work on whatever they like.

You can find out more about YBoard for iPad by clicking here

Author: Paul Saunders

Since the New Year I’ve been using the new Codeacademy website to teach myself how to code “properly”. I’ve never described myself as a developer although I have done quite a bit of “copy and paste” coding over the years. I made a bit of a New Year’s resolution to try and get some more of the basics down and be a bit more self sufficient rather than relying on our dev team all the time.

The Codeacademy Code Year programme was right up my street where weekly lessons are prepared to follow in your own time. Its an excellent course, a superb website and has been getting quite a bit of media and investor attention in the technology world. I’ve been following lessons at lunchtimes and in the evenings with my son and have been enjoying what I have learnt so far. The final lesson this week was a mini app to count up to twenty replacing numbers divisible by 3 with the word “Fizz” and numbers divisible by 5 with the word “Buzz”. It was simple enough, though I did need a bit of help internally to get the modulus syntax spot on. Judging by Twitter there were a few Codeacademy users struggling with this lesson so I thought I’d prepare a bit of a walkthrough. Here it is – I hope it helps, but please don’t visit here each week expecting a cheat sheet!

Exercise 1. Easy as 1, 2, 3
The exercise asks you to write a script to count up to 20. Codeacademy is looking for you to do this using a For Loop. Even if you achieve the same result via other means your answer will be rejected. Here’s my code:

var i;
for (i = 1; i <= 20; i++) {
console.log( + i )
}

I used a variable i which starts at 1 and is returned while stepping up one at a time until i reaches the value 20.

Exercise 2. Fizz
Now you have to modify the script to replace numbers divisible by 3 with the word “Fizz”.  Codeacademy does most of the work for you by showing you the IF ELSE statement. You just need to apply the clause. I used a Modulus to check if i is divisible by 3 leaving a remainder of 0

// Write a statement that decides if the variable `i` is divisible by 3.

// for the numbers 1 through 20,
for ( i=1; i<=20; i++) {

// if the number is divisible by 3, write “Fizz”
if ( i%3===0) {
console.log(“Fizz”);
}

// otherwise, write just the number
else {
console.log(i)
}
}

Exercise 3. Buzz
This exercise is very similar but you need to complete the else if clause to check if the number is divisible by 5. Again a modulus is used here.

// Add an else statement in case the number is divisible by 5.

// for the numbers 1 through 20,
for (i=1; i<=20; i++) {

// if the number is divisible by 3, write “Fizz”
if ( i % 3 === 0 ) {
console.log(“Fizz”);
}

// if the number is divisible by 5, write “Buzz”
else if ( i % 5 === 0 ) {
console.log(“Buzz”);
}

// otherwise, write just the number
else {
console.log(i);
}
}

Exercise 4. FizzBuzz
Now you have to check if any numbers are divisible by both 3 and 5. You need to add an IF clause here that uses an AND logic. I put that clause first so that the other clauses don’t overwrite the variable.

// Add an else statement in case the number is divisible by 5.

// for the numbers 1 through 20,
for (i=1; i<=20; i++) {

// if the number is divisible by 3 and 5 write “FizzBuzz”
if ( i % 3 === 0 && i % 5 === 0 ) {
console.log(“FizzBuzz”);
}

// if the number is divisible by 3, write “Fizz”
else if ( i % 3 === 0 ) {
console.log(“Fizz”);
}

// if the number is divisible by 5, write “Buzz”
else if ( i % 5 === 0 ) {
console.log(“Buzz”);
}

// otherwise, write just the number
else {
console.log(i);
}
}

Exercise 5. Never Gonna Stop
This is the easiest of the lot as all you need to do is change the condition of the FOR loop to stop at 100 instead of 20 [FIXED – thanks Marcin]

// Add an else statement in case the number is divisible by 5.

// for the numbers 1 through 100,
for (i=1; i<=100; i++) {

// if the number is divisible by 3 and 5 write “FizzBuzz”
if ( i % 3 === 0 && i % 5 === 0 ) {
console.log(“FizzBuzz”);
}

// if the number is divisible by 3, write “Fizz”
else if ( i % 3 === 0 ) {
console.log(“Fizz”);
}

// if the number is divisible by 5, write “Buzz”
else if ( i % 5 === 0 ) {
console.log(“Buzz”);
}

// otherwise, write just the number
else {
console.log(i);
}
}

Keep an eye out for more Codeacademy walkthroughs coming soon.

Author: Paul Saunders

## Paul Saunders to present in Miami

Paul Saunders will be presenting for a second year at the Aircraft Commerce Airline & Aerospace MRO & Operations IT Conference – Americas in Miami on the 13th and 14th of March 2012. Paul will be updating and presenting his highly successful workshop “Tablet Stategy Bootcamp” which was warmly received at the Asia/Pacific leg of the conference in Singapore in October 2011.

As well as presenting Paul will also be chairing a round table panel discussion on the use of iPads on the Flight Deck.