Implementing Modules in Node

https://www.codecademy.com/courses/learn-intermediate-javascript/articles/implementing-modules-in-node

/* shape-area.js */
const PI = Math.PI;
const ca = {
  circleArea:function(a){
    return PI*a*a
  },
  squareArea(a,b){
    return a*b
  },
};
module.exports = ca
/* app.js */ 

const ca = require('./shape-area.js');
const circleArea = ca.circleArea;
const squareArea = ca.squareArea;
const areaOfCircle = circleArea(3);
console.log(areaOfCircle);//28.274333882308138
const areaOfSquare = squareArea(2,4);
console.log(areaOfSquare)//4

When i was practicing this lession,there was something wrong with the last code. When squareArea() function with parameters (2,4) was called, number 8 should be printed, i don’t know why number 4 was printed.So why it goes wrong? And how can i solve this problem?

2 Likes

Area of a square should not have 2 different arguments passed, because all sides of a square are equal. Try passing 1 argument instead and see if that changes the answer? I’m currently working through this same article on Learn Intermediate JS as well, so I feel you on this one. Happy keyslappin!
Jose

edit: alos just noticed that SquareArea is not declared as an object property? That might be where the math is gettin foo’d up. Let me know when you solve (or if u already solved) this code challenge. Your post is helping me work thru this right now!