Skip to content

Instantly share code, notes, and snippets.

@cpave3
Created February 3, 2020 06:40
Show Gist options
  • Save cpave3/28dce01034d9c14f92ffe3f41b5bf4c2 to your computer and use it in GitHub Desktop.
Save cpave3/28dce01034d9c14f92ffe3f41b5bf4c2 to your computer and use it in GitHub Desktop.

Bonus Activities

Learning to code isn't just about remembering all the keywords and functions. What you are really learning is a new way of thinking, and solving problems. The language is just a tool to express these thoughts.

Think about the problem at hand, and how you would solve it yourself. The art of problem solving will only get you half way there, the rest of it depends on your ability to take your solution, distill it into its simplest form, and deliver it to the computer in a way that it can understand.

You will make mistakes, and that's okay. This code isn't Mission Critical. No one is in danger, and no money is on the line, so run your code early, and often. Break things, and then fix them again. A good practice is to break the problem down into basic units which you can solve, implement, and test easily, and in isolation of each other.

Another very important thing is how you express your thoughts as code. Generally speaking, simple is good. Complex solutions introduce new places for bugs to hide. The code you write will be read by other people and future you as well, so write with that in mind. Use variable names which explain the purpose of the value stored within.

That little speech aside, here are some exercises to try:

  1. Write a program which prints "Hello, world" to the console.

  2. Write a program which asks the user for their name with a prompt, and then greets them with their name.

    HINT: in javascript, you can stick strings together like this: var greeting = 'Hello there ' + name;

  3. Modify your previous program so that only "Bob" and "Alice" get greeted with their names, and everyone else gets a casual "Hello there"

  4. Write a program that asks the user for a number n and prints the sum of the numbers 1 to n (where n is a value provided by the user)

  5. Modify the previous program such that only multiples of three or five are considered in the sum, e.g. 3, 5, 6, 9, 10, 12, 15 for n=17

  6. Write a program that prints a multiplication table for numbers up to 12.

  7. Write a program which asks the user for an item to add to their shopping list. Each time they provide an item, add it to an array. When the user says "done", stop asking for items, and display the list back to the user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment