Avatar of lujanfernaud

lujanfernaud's solution

to Two Fer (Legacy) in the JavaScript Track

Published at Jul 13 2018 · 0 comments
Test suite


This solution was written on an old version of Exercism. The tests below might not correspond to the solution code, and the exercise may have changed since this code was written.

Two Fer

Two-fer or 2-fer is short for two for one. One for you and one for me.

"One for X, one for me."

When X is a name or "you".

If the given name is "Alice", the result should be "One for Alice, one for me." If no name is given, the result should be "One for you, one for me."


Go through the setup instructions for JavaScript to install the necessary dependencies:


Running the test suite

The provided test suite uses Jasmine. You can install it by opening a terminal window and running the following command:

npm install -g jasmine

Run the test suite from the exercise directory with:

jasmine two-fer.spec.js

In many test suites all but the first test have been marked "pending". Once you get a test passing, activate the next one by changing xit to it.


This is an exercise to introduce users to basic programming constructs, just after Hello World. https://en.wikipedia.org/wiki/Two-fer

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.


var TwoFer = require('./two-fer');

describe('Two Fer', function () {
  var twoFer = new TwoFer();

  it('gives one to you if no parameter given', function () {
    expect(twoFer.twoFer()).toEqual('One for you, one for me.');

  xit('gives one to Alice if \'Alice\' is given', function () {
    expect(twoFer.twoFer('Alice')).toEqual('One for Alice, one for me.');

  xit('gives one to Bob if \'Bob\' is given', function () {
    expect(twoFer.twoFer('Bob')).toEqual('One for Bob, one for me.');
var TwoFer = function () {};

TwoFer.prototype.twoFer = function (who = "you") {
  return `One for ${who}, one for me.`;

module.exports = TwoFer;

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?