Avatar of 4d47

4d47's solution

to Two Fer in the JavaScript Track

Test suite

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.');
module.exports =
class {
  twoFer(who = 'you') {
    return `One for ${who}, one for me.`

What can you learn from this solution?

A huge amount can be learnt 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 I could read more about to develop my understanding?