- Intent: Give Directions
- Context: Provide Examples
- Clarity: Easy to Understand
- Specificity: Precision in Detail
A small demo project to exercise the basic capabilities of Copilot in your IDE. In this demo you should create a Node based calculator Module that you can access from the command-line via an index.js
entry-point. We use copilot to help us with the content creation of the calculator.js
, index,js
and some Node packaging settings. Enjoy !
Note: The demo/workshop only uses Copilot features to complete the solution.
- Make sure to have Copilot, correctly installed & working in your IDE !
- create a project folder (eg.:
myCalulator/
, either in side this Repo or in a new project) - initialize the npm project (create package.json)
- create an
index.js
file - create a
calculator.js
file
mkdir myCalculator
cd myCalculator
npm init
touch index.js
touch calculator.js
mkdir test
touch test/calculator.test.js
1.1 Open the calculator.js
file and add a description comment, explaining to Copilot what this file is for
Help
/**
* @desciption: A calculator module that can add, subtract, multiply, modulo,
* exponent and divide by taking in two numbers and an operator.
* It throws an error if the operator is invalid or if the second
* number is zero and the operator is division.
*
* @param {number} num1
* @param {number} num2
* @param {string} operator
*
* @returns {number} result of the operation
*/
Choose any of the suggested code samples and press Accept Solution
, this will copy the code to the file.
Help
/**
* @description This is a simple function that takes in two numbers, an operator
* and uses the calculator module to compute the results.
* Usage:
* node index2.js 1 + 2
* node index2.js 1 - 2
* node index2.js 1 * 2
* node index2.js 1 / 2
*
* Note: The * and ^ operators need to be escaped with a backslash, to prevent the shell from interpreting them.
* Example: node index2.js 1 \* 2
*
*/
Choose any of the suggested code samples and press Accept Solution
, this will copy the code to the file.
node index.js
or
node index.js 2 + 3
This section is open to your imagination, try to "challenge" the code. See if you find use-cases that "break it".