The aim of this lab is to familarise yourself with GIT, and learn how to use it for projects.
Run through this basic introduction from Code School.
To become an expert at using GIT, run through the full tutorial from Atlassian.
GitHub is a online application used for hosting GIT repositories. It can be used to store your code, collaborate with others, manage version control, and many other things.
Set up a GitHub account (if you haven't got one already). You can get a student account. This is important as it will allow you to make free, private repositories, so no other students can accidently find and borrow your code.
For practise, work with a partner to create a joint GitHub project. Link the project with your individual development environments, then try a series of commits, pushes, checkouts (forks) and merges, and then undo them.
Run through this tutorial on using GIT with VScode.
Create a new web page, calculator.html
, based on your template page. Add a text-based input field, and a
"Calculate" button. When the button is pressed, Javascript (and jQuery) should parse the equation given in the input field,
and create a p
element with the equation and the solution. You may assume for now that the formula
contains at most three operations.
Note: Be sure to add a description of how to use this calculator!
You will need to use the regular expression methods to parse, or break down, the string into its components, and type conversion to extract the numbers. When doing the parsing, remember to respect the precedence of the arithmetic operators. For example, if the user enters:
15 + 4 x 3it should give the answer 27, not 57.
Note: Be sure to ignore any whitespaces.
Repeat the above task for arbitrary length formulae using an array as a Stack data structure (that is, using the push and pop methods). See here if you are not familar with stacks.
You will need three stacks:
You may assume that only natural numbers and no parentheses will be entered.
The algorithm proceeds as follows:
input stack preorder stack 1x2+3x4+5 empty 3x4+5, 1x2 + 3x4+5, 2, 1 +, x 3x4+5, 2 +, x, 1 3x4+5 +, x, 1, 2 5, 3x4 +, x, 1, 2, + ... empty +, x, 1, 2, +, x, 3, 4, 5
preorder stack answer stack +, x, 1, 2, +, x, 3, 4, 5 empty +, x, 1, 2, +, x, 3, 4 5 +, x, 1, 2, +, x, 3 5, 4 +, x, 1, 2, +, x 5, 4, 3 +, x, 1, 2, + 5, 12 +, x, 1, 2 17 ... empty 19
To help debugging, write code that prints the contents of the stacks out in the browser window at each step, like the examples above.