http://robertdunaway.github.io
TypeScript code kata list
All code kata lists
008 TypeScript - operators
Duration
10 minutes
Brief
Using many types of operators.
For more information
BING/GOOGLE: “TypeScript operators”
Instructions
Get tutorial folder or the entire katas-typescript repo.
Open the [before/*.sln]
file and execute the kata.
Feel free to execute this kata multiple times because repetition creates motor memory.
Github
- Before (start kata with this)
- After
Kata
Create two variables of type number. These can be used throughout this kata.
var a: number = 10;
var b: number = 5;
Output to the console the addition, subtraction, multiplication, and division of these numbers.
console.log('a + b = ' + (a + b));
console.log('a - b = ' + (a - b));
console.log('a * b = ' + (a * b));
console.log('a / b = ' + (a / b));
Output to the console the remainder of two divided numbers that yield no remainder and again where a remainder is present.
Tip: The % operator is used.
console.log('a % b = ' + (a % b));
console.log('a % b = ' + (a % 6));
Increment and decrement “a” with operators.
a++;
console.log('a++ = ' + a);
a--;
console.log('a-- = ' + a);
a--;
console.log('a-- = ' + a);
Next
Take a few minutes and imagine more examples.
0 comments:
Post a Comment