Q:

I'm trying to create a calculator but it won't give me any results

I'm trying to make a pretty basic multiplication calculator and for some reason it won't actually calculate any results. I'm not sure what I'm doing wrong, but I'll attach screenshots of each part of my code that I have so far.

Thanks in advance for any help/advice!

(Also I'm not entirely sure how to post/attach my code in this post, I apologize!)

A:

I just made a Calculator for someone else on this site about 10 minutes ago.
Here's my code
function Calculator(initialNum) {

  var result = 0;

  // private api
  function set(num) {
    return result = num || 0;
  }

  function add(num) {
    return set(result + num);
  }

  function subtract(num) {
    return set(result - num);
  }

  function divide(num) {
    if (num === 0) throw new Error("Cannot divide by zero");
    return set(result / num);
  }

  function multiply(num) {
    return set(result * num);
  }

  function value() {
    return result;
  }

  function clear() {
    return set(0);
  }

  // exports; public api
  this.add      = add;
  this.subtract = subtract;
  this.divide   = divide;
  this.multiply = multiply;
  this.value    = value;
  this.clear    = clear;

  // "magic" api
  this.valueOf = value;

  // init
  set(initialNum);
}

Usage
var a = new Calculator; // 0
a.add(5);               // 5
a.add(10);              // 15
a.divide(5);            // 3
a.multiply(3);          // 9

Calculators can work with each other too
var b = new Calculator(3);  // 3
b.add(3);               // 6
b.multiply(a);          // 54
b.clear();              // 0
+a;                     // 9

