Portfolio: Kata Exercises

Kata Exercises

These are a series of Kata exercises given in GWDB123: Programming Fundamentals to practice JavaScript concepts learned in class.

About Kata

Big Picture

Kata, loosely, are forms practiced over and over. The term comes from the martial arts (Japanese, mostly). In The Pragmatic Programmer (same source as Rubber Ducky Debugging), kata is a term given to programming exercises to focus and hone skills and concepts. Kata are not intended to be a ‘one and done’ exercise, but repeated multiple times. This is not to say you write the same thing over and over again. Instead, each attempt at a kata should be made from a different angle or perspective than previous attempts. In other words: to look at a the kata problem a different way and try a different solution.

Practice, practice, practice

For our purposes, kata are exercises to try skills and concepts learned in class. Many kata posted will have variations or levels of complexity to challenge different skill levels. Submitted kata receive XP that is applied towards the grade total. The higher the kata skill level attempted, the higher the associated XP. Kata may be attempted multiple times for more XP. However, kata submitted for more XP much each have a different solution. Kata submitted with the same solution are treated as resubmissions and do not receive more XP.

Here’s an example: Kwaqs the hacker duck completes a kata and submits the attempt and receives 25 XP for the attempt. Kwaqs learns some new stuff and decides to make another attempt at the kata, this time with a different solution. Kwaqs receives 20 XP (out of a possible 25) for the second attempt because the 2nd attempt didn’t work correctly. Kwaqs discovers the bug in the code, fixes the code, and resubmits the kata. Kwaqs doesn’t receive another set of 25 XP for the fixed code–just a few more points for fixing and resubmitting (the full 25 out of 25 for the second attempt).

Clear as mud?

Submitting kata

When submitting kata, be sure to indicate which level (if multiple levels offered for the kata) is attempted. Provide some details about the solution attempted: How did you approach the solution? What was different from the last submission (if making more than one attempt)? How well do you think your solution worked? What would you change to improve the solution?

Kata: Communicating in binary

Binary is the language computers speak: everything is broken down to 1’s and 0’s (bits). Computer memory is made up of a ‘honeycomb’ of units called ‘bytes’. There are 8 bits in one byte. One character, this letter A for example, is one byte of data that is stored in memory using the following bits: 0100001.

See the BBC education guide Introducing Binary at https://www.bbc.co.uk/education/guides/zwsbwmn/revision to learn more about computers and binary.

N00b-level: Refer to the ASCII chart in Appendix A (or Google ASCII chart). Write your name out in binary characters.

XP: 10

Code monkey-level: Write, pseudocode, an algorithm that inputs a string of text, converts the characters to binary, and outputs the binary version of the string input.

XP: 25

King Code-level: Write a JavaScript program that collects text input from a user, converts the text to binary, and outputs what the user input and the converted binary.

XP: 50

Unicorn-level: Complete the King Code level with at least three of these additions:

XP: 100

  • Receives binary as input and outputs the corresponding characters.
  • Write a function that tests your program with different data values to see where your program breaks. Fix the breaks.
  • Use Unicode instead of ASCII. Allow conversion to and from binary of emojis, non-english alphabet characters, and numbers.
  • Utilize the browser DOM to create element and text nodes to display converted output.
  • Create a game for the user to guess or match binary values to character and/or number values.
  • Design a means to display the binary output using something other than 1’s and 0’s. (e.g. make it art).

Kata: Mad Libs

Mad Libs is a classic word game where one player prompts another player for words of a particular type (sound, adjective, verb, etc.). The words the second player offers up are inserted into a story and the story is read aloud, often to funny or non-sensical results. To complete this kata, you will need to acquire an actual Mad Libs text and word list.

Wikipedia: Mad Libs

N00b: Design a program, using pseudocode and flowcharts that asks the user for a series of words from the word list, then outputs the completed Mad Libs story, inserting the words the user entered where appropriate. Indicate in your program design the inputs and outputs required.

XP: 20

Code Monkey: Complete the Noob kata. Based on the algorithm/program designed, create a JavaScript program that executes the program as designed.

XP: 50

King Code: Complete the Noob and Code Monkey kata. Refine the solution for improved efficiency for data input, storage, retrieval. Randomly display a different Mad Lib story so the user doesn’t always get the same results.

XP: 75

Unicorn: Complete the King Code level. Add data validation for user input. Allow the user the opportunity to change their input and see the changes updated in the displayed Mad Lib. Create a function that tests the data validation.

XP: 100

Kata: Travel Time and Cost

Here we have the classic problem of calculating the amount of time to travel a given distance at a given speed. We’ll add to the problem by also calculating how much gasoline was used based on a given MPG and how much the gasoline cost, based on a given price per gallon.

N00b: Write, in pseudocode, an algorithm that accepts the following input: distance travelled, speed (rate), MPG, and cost per gallon. The pseudocode should show calculating the amount of time spent traveling and how much the trip cost. Finally, the pseudocode demonstrates outputting what the user entered and the calculated values, formatted to indicate what’s what.

XP: 20

Code Monkey: Complete the Noob level. Using your pseudocode as a guide, create a JavaScript program that asks for the required input, calculates the required values, and outputs the results to the user.

XP: 50

King Code: Complete the Code Monkey and Noob levels. Add to your program some additional “smarts”: The program requests input for all possible data points: distance, speed, time, gas used (in gallons), MPG, price per gallon, and total cost. The program can then calculate the missing values based on what was submitted. For example, given the total cost for the trip and the distance travelled, the program can output the price per gallon. Likewise, given the time and speed, the program can output the distance travelled.

XP: 75

Unicorn: Complete the King Code level. Use form elements with labels to collect the user input. Dynamically calculate and update the values of the text fields as the user enters input. Display suitable error, processing or waiting messages to the user as appropriate while user is entering input. Check user input for validity. Allow user to switch between English and metric units.

Note: you may need the onclick event handler. Some other event handlers you might find useful for forms are onblur, onfocus, and onchange. Radio buttons can work well for a English/metric toggle.

XP: 100

Kata: Yahtzee

Yahtzee is a classic dice game. The object is to score the most points in a game. To score, a player rolls 5 6-sided dice. The player can choose to re-roll all or some of their dice up to three times. The player decides on a scoring category for their roll. Points for that award are based on the compatibility of the roll results. When all the categories are scored, the game is over. The player with the most points wins.

Yahtzee rules, according to Wikipedia: https://en.wikipedia.org/wiki/Yahtzee

N00b: Write an algorithm, in pseudocode and as a flowchart, that outlines how a Yahtzee game would be programmed. The flowchart may need to be broken up in to multiple sections for clarity.

XP: 50 points

Code Monkey: Complete the Noob level. Build on that by creating a HTML/JavaScript-based version of the Yahtzee game. This program would rely on the user providing most of the decision-making (i.e. selecting which category to score a round in). The program would need to display the score for the round for the selected category and the updated total score after each round. This game would also be a ‘solitaire’ version with users playing against themselves. A round would include three rolls and a category choice for scoring. The game is over when all categories are scored.

XP: 100 points

King Code: Complete the Noob and Code Monkey levels. Add to the Code Monkey level a multiplayer option where each player takes a turn. The user can select the number of players and players’ names at the start of the game. The game needs to keep track of and display each players’ score for the round and total score. It also needs to keep track of which player is currently playing. The winning player is indicated at the end of the game.

XP: 150 points

Unicorn: Complete the King Code level. Add to that some decision-making capability to the game. The game displays the possible score for each category, based on the current roll and highlights the highest-scoring category. Already scored categories should be excluded. Additionally, the game (computer) can play as one of the players.

XP: 200 points