Skip to content

Instantly share code, notes, and snippets.

View Rukeeo1's full-sized avatar

Rukee Ojigbo Rukeeo1

  • Decagon Institute
  • Lagos
View GitHub Profile
@Rukeeo1
Rukeeo1 / user.test.js
Created May 6, 2019 12:00
test cases for user.test.js
/* import the User constructor*/
const User = require("./user_constructor").User;
//..create dummy users for test purposes
let userOne = new User("John Doe");
let userTwo = new User("Jane Doe");
let userThree = new User("Bill Clinton");
describe("testing that the constructor function returns an object", function() {
it("should return 'object'", function() {
@Rukeeo1
Rukeeo1 / user.js
Last active May 6, 2019 11:55
User Constructor Code...this is for my article on object oriented programming
/* a userArray to serve as database for storing Users */
let userArray = [];
/* create an Id variable set it to zero and auto increment it each time the user constructor is called */
let id = 0;
/* A User constructor to create users */
function User(name) {
this.name = name;
accountBalance = this.accountBalance = 0;
function addNumber(a, b) {
return typeof a !== "number" || typeof b !== "number"
? "first and second parameter's must be numbers"
: Number((a + b).toFixed(2));
}
/* Export the addNumber function to app.test.js */
module.exports = addNumber;
@Rukeeo1
Rukeeo1 / app.js
Last active May 6, 2019 08:51
The addNumber function returns the sum of two Integers
function addNumber(a, b) {
//check to see that 'a' and 'b' are numbers
if (typeof a !== "number" || typeof b !== "number") {
return "first and second parameter's must be numbers";
}
/* sum both numbers */
let sum = a + b;
/* if it's an Integer return 'sum', else for floating point numbers approximate to two decimal place*/