<commit_before>
QUnit.module('Primitives');

QUnit.test('Two.Points', function(assert) {

  var props = Two.Points.Properties.slice(0, 7);

  assert.expect(props.length + 13);

  var two = new Two();
  var points = new Two.Points();
  two.add(points);
  two.update();

  points = new Two.Points([
    new Two.Vector(0, 0),
    new Two.Vector(100, 100),
    new Two.Vector(200, 200),
    new Two.Vector(300, 300)
  ]);

  assert.equal(points.vertices.length, 4, 'Amount of vertices set correctly.');

  points.fill = 'red';
  assert.equal(points.fill, 'red', 'Can get property fill correctly.');
  assert.equal(points._fill, 'red', 'Can set property fill correctly.');

  points.stroke = 'red';
  assert.equal(points.stroke, 'red', 'Can get property stroke correctly.');
  assert.equal(points._stroke, 'red', 'Can set property stroke correctly.');

  points.size = 6;
  assert.equal(points.size, 6, 'Can get property size correctly.');
  assert.equal(points._size, 6, 'Can set property size correctly.');

  points.sizeAttenuation = true;
  assert.equal(points.sizeAttenuation, true, 'Can get property sizeAttenuation correctly.');
  assert.equal(points._sizeAttenuation, true, 'Can set property sizeAttenuation correctly.');

  points.dashes = [2, 2];
  assert.equal(points.dashes.length === 2 && points.dashes[0] === 2 && points.dashes[1] === 2, true, 'Can get property dashes correctly.');
  assert.equal(points._dashes.length === 2 && points._dashes[0] === 2 && points._dashes[1] === 2, true, 'Can set property dashes correctly.');

  points.className = 'ui-points';
  assert.equal(points.className, 'ui-points', 'Can get property className correctly.');
  assert.equal(points._className, 'ui-points', 'Can set property className correctly.');

  points._update();
  points.flagReset();

  for (var i = 0; i < props.length; i++) {
    var prop = props[i];
    assert.equal(points['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], false, 'Reset flag ' + prop + ' correctly.');
  }

  points.beginning = 0.5;
  points.ending = 0.5;
  two.add(points);
  two.update();

});

QUnit.test('Two.ArcSegment', function(assert) {

  assert.expect(Two.ArcSegment.Properties.length * 4 + 2);

  var innerRadius = 5;
  var outerRadius = 10;
  var startAngle = 0;
  var endAngle = Math.PI / 2;

  var properties = [
    startAngle, endAngle, innerRadius, outerRadius
  ];

  var path = new Two.ArcSegment(0, 0, innerRadius, outerRadius, startAngle, endAngle);
  assert.equal(path.vertices.length, Two.Resolution * 3, 'Amount of vertices set correctly.');

  for (var i = 0; i < Two.ArcSegment.Properties.length; i++) {
    var prop = Two.ArcSegment.Properties[i];
    assert.equal(path[prop], properties[i], 'Can get property ' + prop + ' correctly.');
    path[prop] = properties[i] * 2;
    assert.equal(path[prop], properties[i] * 2, 'Can set property ' + prop + ' correctly.');
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], true, 'Set ' + prop + '\'s property flag correctly.');
  }

  path._update();
  path.flagReset();

  for (var i = 0; i < Two.ArcSegment.Properties.length; i++) {
    var prop = Two.ArcSegment.Properties[i];
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], false, 'Reset flag ' + prop + ' correctly.');
  }

  path.closed = false;
  path._update();

  assert.equal(path.vertices[0].equals(path.vertices[path.vertices.length - 1]), true, 'Circle has standardized vertex generation when shape is not closed');

});

QUnit.test('Two.Circle', function(assert) {

  assert.expect(Two.Circle.Properties.length * 4 + 2);

  var radius = 50;
  var properties = [radius];

  var path = new Two.Circle(0, 0, radius);
  assert.equal(path.vertices.length, 4, 'Amount of vertices set correctly.');

  for (var i = 0; i < Two.Circle.Properties.length; i++) {
    var prop = Two.Circle.Properties[i];
    assert.equal(path[prop], properties[i], 'Can get property ' + prop + ' correctly.');
    path[prop] = properties[i] * 2;
    assert.equal(path[prop], properties[i] * 2, 'Can set property ' + prop + ' correctly.');
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], true, 'Set ' + prop + '\'s property flag correctly.');
  }

  path._update();
  path.flagReset();

  for (var i = 0; i < Two.Circle.Properties.length; i++) {
    var prop = Two.Circle.Properties[i];
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], false, 'Reset flag ' + prop + ' correctly.');
  }

  path.closed = false;
  path._update();

  assert.equal(path.vertices[0].equals(path.vertices[path.vertices.length - 1]), true, 'Circle has standardized vertex generation when shape is not closed');

});

QUnit.test('Two.Ellipse', function(assert) {

  assert.expect(Two.Ellipse.Properties.length * 4 + 2);

  var rx = 50;
  var ry = 75;
  var properties = [rx * 2, ry * 2];

  var path = new Two.Ellipse(0, 0, rx, ry);
  assert.equal(path.vertices.length, 4, 'Amount of vertices set correctly.');

  for (var i = 0; i < Two.Ellipse.Properties.length; i++) {
    var prop = Two.Ellipse.Properties[i];
    assert.equal(path[prop], properties[i], 'Can get property ' + prop + ' correctly.');
    path[prop] = properties[i] * 2;
    assert.equal(path[prop], properties[i] * 2, 'Can set property ' + prop + ' correctly.');
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], true, 'Set ' + prop + '\'s property flag correctly.');
  }

  path._update();
  path.flagReset();

  for (var i = 0; i < Two.Ellipse.Properties.length; i++) {
    var prop = Two.Ellipse.Properties[i];
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], false, 'Reset flag ' + prop + ' correctly.');
  }

  path.closed = false;
  path._update();

  assert.equal(path.vertices[0].equals(path.vertices[path.vertices.length - 1]), true, 'Ellipse has standardized vertex generation when shape is not closed');

});

QUnit.test('Two.Polygon', function(assert) {

  assert.expect(Two.Polygon.Properties.length * 4 + 1);

  var radius = 50;
  var sides = 5;
  var properties = [radius * 2, radius * 2, sides];

  var path = new Two.Polygon(0, 0, radius, sides);

  for (var i = 0; i < Two.Polygon.Properties.length; i++) {
    var prop = Two.Polygon.Properties[i];
    assert.equal(path[prop], properties[i], 'Can get property ' + prop + ' correctly.');
    path[prop] = properties[i] * 2;
    assert.equal(path[prop], properties[i] * 2, 'Can set property ' + prop + ' correctly.');
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], true, 'Set ' + prop + '\'s property flag correctly.');
  }

  path._update();
  path.flagReset();

  for (var i = 0; i < Two.Polygon.Properties.length; i++) {
    var prop = Two.Polygon.Properties[i];
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], false, 'Reset flag ' + prop + ' correctly.');
  }

  path.closed = false;
  path._update();

  assert.equal(path.vertices[0].equals(path.vertices[path.vertices.length - 1]), true, 'Polygon has standardized vertex generation when shape is not closed');

});

QUnit.test('Two.Rectangle', function(assert) {

  assert.expect(Two.Rectangle.Properties.length * 4 + 1);

  var width = 50;
  var height = 75;
  var properties = [width, height];

  var path = new Two.Rectangle(0, 0, width, height);

  for (var i = 0; i < Two.Rectangle.Properties.length; i++) {
    var prop = Two.Rectangle.Properties[i];
    assert.equal(path[prop], properties[i], 'Can get property ' + prop + ' correctly.');
    path[prop] = properties[i] * 2;
    assert.equal(path[prop], properties[i] * 2, 'Can set property ' + prop + ' correctly.');
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], true, 'Set ' + prop + '\'s property flag correctly.');
  }

  path._update();
  path.flagReset();

  for (var i = 0; i < Two.Rectangle.Properties.length; i++) {
    var prop = Two.Rectangle.Properties[i];
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], false, 'Reset flag ' + prop + ' correctly.');
  }

  path.closed = false;
  path._update();

  assert.equal(path.vertices[0].equals(path.vertices[path.vertices.length - 1]), true, 'Rectangle has standardized vertex generation when shape is not closed');

});

QUnit.test('Two.RoundedRectangle', function(assert) {

  assert.expect(Two.RoundedRectangle.Properties.length * 4 + 5);

  var width = 50;
  var height = 75;
  var radius = 8;
  var properties = [width, height];

  var path = new Two.RoundedRectangle(0, 0, width, height, radius);

  for (var i = 0; i < Two.RoundedRectangle.Properties.length; i++) {
    var prop = Two.RoundedRectangle.Properties[i];
    assert.equal(path[prop], properties[i], 'Can get property ' + prop + ' correctly.');
    path[prop] = properties[i] * 2;
    assert.equal(path[prop], properties[i] * 2, 'Can set property ' + prop + ' correctly.');
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], true, 'Set ' + prop + '\'s property flag correctly.');
  }

  assert.equal(path.radius, radius, 'Can get property radius correctly.');
  path.radius = radius * 2;
  assert.equal(path.radius, radius * 2, 'Can set property radius correctly.');
  assert.equal(path._flagRadius, true, 'Set radius\' flag correctly.');

  // TODO: Test Vector based radius.

  path._update();
  path.flagReset();

  for (var i = 0; i < Two.RoundedRectangle.Properties.length; i++) {
    var prop = Two.RoundedRectangle.Properties[i];
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], false, 'Reset flag ' + prop + ' correctly.');
  }

  assert.equal(path._flagRadius, false, 'Reset flag radius correctly.');

  path.closed = false;
  path._update();

  assert.equal(path.vertices[0].equals(path.vertices[path.vertices.length - 1]), true, 'RoundedRectangle has standardized vertex generation when shape is not closed');

});

QUnit.test('Two.Star', function(assert) {

  assert.expect(Two.Star.Properties.length * 4 + 1);

  var innerRadius = 50;
  var outerRadius = 75;
  var sides = 5;
  var properties = [innerRadius, outerRadius, sides];

  var path = new Two.Star(0, 0, innerRadius, outerRadius, sides);

  for (var i = 0; i < Two.Star.Properties.length; i++) {
    var prop = Two.Star.Properties[i];
    assert.equal(path[prop], properties[i], 'Can get property ' + prop + ' correctly.');
    path[prop] = properties[i] * 2;
    assert.equal(path[prop], properties[i] * 2, 'Can set property ' + prop + ' correctly.');
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], true, 'Set ' + prop + '\'s property flag correctly.');
  }

  path._update();
  path.flagReset();

  for (var i = 0; i < Two.Star.Properties.length; i++) {
    var prop = Two.Star.Properties[i];
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], false, 'Reset flag ' + prop + ' correctly.');
  }

  path.closed = false;
  path._update();

  assert.equal(path.vertices[0].equals(path.vertices[path.vertices.length - 1]), true, 'Star has standardized vertex generation when shape is not closed');

});
<commit_msg>Cleaned Up Two.RoundedRectangle Tests<commit_after>
QUnit.module('Primitives');

QUnit.test('Two.Points', function(assert) {

  var props = Two.Points.Properties.slice(0, 7);

  assert.expect(props.length + 13);

  var two = new Two();
  var points = new Two.Points();
  two.add(points);
  two.update();

  points = new Two.Points([
    new Two.Vector(0, 0),
    new Two.Vector(100, 100),
    new Two.Vector(200, 200),
    new Two.Vector(300, 300)
  ]);

  assert.equal(points.vertices.length, 4, 'Amount of vertices set correctly.');

  points.fill = 'red';
  assert.equal(points.fill, 'red', 'Can get property fill correctly.');
  assert.equal(points._fill, 'red', 'Can set property fill correctly.');

  points.stroke = 'red';
  assert.equal(points.stroke, 'red', 'Can get property stroke correctly.');
  assert.equal(points._stroke, 'red', 'Can set property stroke correctly.');

  points.size = 6;
  assert.equal(points.size, 6, 'Can get property size correctly.');
  assert.equal(points._size, 6, 'Can set property size correctly.');

  points.sizeAttenuation = true;
  assert.equal(points.sizeAttenuation, true, 'Can get property sizeAttenuation correctly.');
  assert.equal(points._sizeAttenuation, true, 'Can set property sizeAttenuation correctly.');

  points.dashes = [2, 2];
  assert.equal(points.dashes.length === 2 && points.dashes[0] === 2 && points.dashes[1] === 2, true, 'Can get property dashes correctly.');
  assert.equal(points._dashes.length === 2 && points._dashes[0] === 2 && points._dashes[1] === 2, true, 'Can set property dashes correctly.');

  points.className = 'ui-points';
  assert.equal(points.className, 'ui-points', 'Can get property className correctly.');
  assert.equal(points._className, 'ui-points', 'Can set property className correctly.');

  points._update();
  points.flagReset();

  for (var i = 0; i < props.length; i++) {
    var prop = props[i];
    assert.equal(points['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], false, 'Reset flag ' + prop + ' correctly.');
  }

  points.beginning = 0.5;
  points.ending = 0.5;
  two.add(points);
  two.update();

});

QUnit.test('Two.ArcSegment', function(assert) {

  assert.expect(Two.ArcSegment.Properties.length * 4 + 2);

  var innerRadius = 5;
  var outerRadius = 10;
  var startAngle = 0;
  var endAngle = Math.PI / 2;

  var properties = [
    startAngle, endAngle, innerRadius, outerRadius
  ];

  var path = new Two.ArcSegment(0, 0, innerRadius, outerRadius, startAngle, endAngle);
  assert.equal(path.vertices.length, Two.Resolution * 3, 'Amount of vertices set correctly.');

  for (var i = 0; i < Two.ArcSegment.Properties.length; i++) {
    var prop = Two.ArcSegment.Properties[i];
    assert.equal(path[prop], properties[i], 'Can get property ' + prop + ' correctly.');
    path[prop] = properties[i] * 2;
    assert.equal(path[prop], properties[i] * 2, 'Can set property ' + prop + ' correctly.');
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], true, 'Set ' + prop + '\'s property flag correctly.');
  }

  path._update();
  path.flagReset();

  for (var i = 0; i < Two.ArcSegment.Properties.length; i++) {
    var prop = Two.ArcSegment.Properties[i];
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], false, 'Reset flag ' + prop + ' correctly.');
  }

  path.closed = false;
  path._update();

  assert.equal(path.vertices[0].equals(path.vertices[path.vertices.length - 1]), true, 'Circle has standardized vertex generation when shape is not closed');

});

QUnit.test('Two.Circle', function(assert) {

  assert.expect(Two.Circle.Properties.length * 4 + 2);

  var radius = 50;
  var properties = [radius];

  var path = new Two.Circle(0, 0, radius);
  assert.equal(path.vertices.length, 4, 'Amount of vertices set correctly.');

  for (var i = 0; i < Two.Circle.Properties.length; i++) {
    var prop = Two.Circle.Properties[i];
    assert.equal(path[prop], properties[i], 'Can get property ' + prop + ' correctly.');
    path[prop] = properties[i] * 2;
    assert.equal(path[prop], properties[i] * 2, 'Can set property ' + prop + ' correctly.');
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], true, 'Set ' + prop + '\'s property flag correctly.');
  }

  path._update();
  path.flagReset();

  for (var i = 0; i < Two.Circle.Properties.length; i++) {
    var prop = Two.Circle.Properties[i];
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], false, 'Reset flag ' + prop + ' correctly.');
  }

  path.closed = false;
  path._update();

  assert.equal(path.vertices[0].equals(path.vertices[path.vertices.length - 1]), true, 'Circle has standardized vertex generation when shape is not closed');

});

QUnit.test('Two.Ellipse', function(assert) {

  assert.expect(Two.Ellipse.Properties.length * 4 + 2);

  var rx = 50;
  var ry = 75;
  var properties = [rx * 2, ry * 2];

  var path = new Two.Ellipse(0, 0, rx, ry);
  assert.equal(path.vertices.length, 4, 'Amount of vertices set correctly.');

  for (var i = 0; i < Two.Ellipse.Properties.length; i++) {
    var prop = Two.Ellipse.Properties[i];
    assert.equal(path[prop], properties[i], 'Can get property ' + prop + ' correctly.');
    path[prop] = properties[i] * 2;
    assert.equal(path[prop], properties[i] * 2, 'Can set property ' + prop + ' correctly.');
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], true, 'Set ' + prop + '\'s property flag correctly.');
  }

  path._update();
  path.flagReset();

  for (var i = 0; i < Two.Ellipse.Properties.length; i++) {
    var prop = Two.Ellipse.Properties[i];
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], false, 'Reset flag ' + prop + ' correctly.');
  }

  path.closed = false;
  path._update();

  assert.equal(path.vertices[0].equals(path.vertices[path.vertices.length - 1]), true, 'Ellipse has standardized vertex generation when shape is not closed');

});

QUnit.test('Two.Polygon', function(assert) {

  assert.expect(Two.Polygon.Properties.length * 4 + 1);

  var radius = 50;
  var sides = 5;
  var properties = [radius * 2, radius * 2, sides];

  var path = new Two.Polygon(0, 0, radius, sides);

  for (var i = 0; i < Two.Polygon.Properties.length; i++) {
    var prop = Two.Polygon.Properties[i];
    assert.equal(path[prop], properties[i], 'Can get property ' + prop + ' correctly.');
    path[prop] = properties[i] * 2;
    assert.equal(path[prop], properties[i] * 2, 'Can set property ' + prop + ' correctly.');
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], true, 'Set ' + prop + '\'s property flag correctly.');
  }

  path._update();
  path.flagReset();

  for (var i = 0; i < Two.Polygon.Properties.length; i++) {
    var prop = Two.Polygon.Properties[i];
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], false, 'Reset flag ' + prop + ' correctly.');
  }

  path.closed = false;
  path._update();

  assert.equal(path.vertices[0].equals(path.vertices[path.vertices.length - 1]), true, 'Polygon has standardized vertex generation when shape is not closed');

});

QUnit.test('Two.Rectangle', function(assert) {

  assert.expect(Two.Rectangle.Properties.length * 4 + 1);

  var width = 50;
  var height = 75;
  var properties = [width, height];

  var path = new Two.Rectangle(0, 0, width, height);

  for (var i = 0; i < Two.Rectangle.Properties.length; i++) {
    var prop = Two.Rectangle.Properties[i];
    assert.equal(path[prop], properties[i], 'Can get property ' + prop + ' correctly.');
    path[prop] = properties[i] * 2;
    assert.equal(path[prop], properties[i] * 2, 'Can set property ' + prop + ' correctly.');
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], true, 'Set ' + prop + '\'s property flag correctly.');
  }

  path._update();
  path.flagReset();

  for (var i = 0; i < Two.Rectangle.Properties.length; i++) {
    var prop = Two.Rectangle.Properties[i];
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], false, 'Reset flag ' + prop + ' correctly.');
  }

  path.closed = false;
  path._update();

  assert.equal(path.vertices[0].equals(path.vertices[path.vertices.length - 1]), true, 'Rectangle has standardized vertex generation when shape is not closed');

});

QUnit.test('Two.RoundedRectangle', function(assert) {

  assert.expect(Two.RoundedRectangle.Properties.length * 4 + 3);

  var width = 50;
  var height = 75;
  var radius = 8;
  var properties = [width, height, radius];

  var path = new Two.RoundedRectangle(0, 0, width, height, radius);

  for (var i = 0; i < Two.RoundedRectangle.Properties.length; i++) {
    var prop = Two.RoundedRectangle.Properties[i];
    assert.equal(path[prop], properties[i], 'Can get property ' + prop + ' correctly.');
    path[prop] = properties[i] * 2;
    assert.equal(path[prop], properties[i] * 2, 'Can set property ' + prop + ' correctly.');
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], true, 'Set ' + prop + '\'s property flag correctly.');
  }

  radius = new Two.Vector(4, 6);
  path.radius = radius.clone();
  assert.equal(radius.equals(path.radius), true, 'Can get and set radius as a vector correctly.');

  path._update();
  path.flagReset();

  for (var i = 0; i < Two.RoundedRectangle.Properties.length; i++) {
    var prop = Two.RoundedRectangle.Properties[i];
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], false, 'Reset flag ' + prop + ' correctly.');
  }

  assert.equal(path._flagRadius, false, 'Reset flag radius correctly.');

  path.closed = false;
  path._update();

  assert.equal(path.vertices[0].equals(path.vertices[path.vertices.length - 1]), true, 'RoundedRectangle has standardized vertex generation when shape is not closed');

});

QUnit.test('Two.Star', function(assert) {

  assert.expect(Two.Star.Properties.length * 4 + 1);

  var innerRadius = 50;
  var outerRadius = 75;
  var sides = 5;
  var properties = [innerRadius, outerRadius, sides];

  var path = new Two.Star(0, 0, innerRadius, outerRadius, sides);

  for (var i = 0; i < Two.Star.Properties.length; i++) {
    var prop = Two.Star.Properties[i];
    assert.equal(path[prop], properties[i], 'Can get property ' + prop + ' correctly.');
    path[prop] = properties[i] * 2;
    assert.equal(path[prop], properties[i] * 2, 'Can set property ' + prop + ' correctly.');
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], true, 'Set ' + prop + '\'s property flag correctly.');
  }

  path._update();
  path.flagReset();

  for (var i = 0; i < Two.Star.Properties.length; i++) {
    var prop = Two.Star.Properties[i];
    assert.equal(path['_flag' + prop.charAt(0).toUpperCase() + prop.slice(1)], false, 'Reset flag ' + prop + ' correctly.');
  }

  path.closed = false;
  path._update();

  assert.equal(path.vertices[0].equals(path.vertices[path.vertices.length - 1]), true, 'Star has standardized vertex generation when shape is not closed');

});
<|endoftext|>


<commit_before>import { TOGGLE_PLAY_ON_HOVER, TOGGLE_METRONOME_SOUND,
  SET_SHOULD_PLAY_ON_HOVER, TOGGLE_CLUSTER_TAGS } from './actions';
import storable from '../SessionsHandler/storableReducer';

export const initialState = {
  shouldPlayOnHover: false,
  shouldPlayMetronomeSound: false,
  shouldShowClusterTags: false,
};

const settings = (state = initialState, action) => {
  switch (action.type) {
    case TOGGLE_PLAY_ON_HOVER: {
      return Object.assign({}, state, {
        shouldPlayOnHover: !state.shouldPlayOnHover,
      });
    }
    case SET_SHOULD_PLAY_ON_HOVER: {
      return Object.assign({}, state, {
        shouldPlayOnHover: action.shouldPlayOnHover,
      });
    }
    case TOGGLE_METRONOME_SOUND: {
      return Object.assign({}, state, {
        shouldPlayMetronomeSound: !state.shouldPlayMetronomeSound,
      });
    }
    case TOGGLE_CLUSTER_TAGS: {
      return Object.assign({}, state, {
        shouldShowClusterTags: !state.shouldShowClusterTags,
      });
    }
    default:
      return state;
  }
};

export default storable(settings);
<commit_msg>Enables showing the ClusterTags by default<commit_after>import { TOGGLE_PLAY_ON_HOVER, TOGGLE_METRONOME_SOUND,
  SET_SHOULD_PLAY_ON_HOVER, TOGGLE_CLUSTER_TAGS } from './actions';
import storable from '../SessionsHandler/storableReducer';

export const initialState = {
  shouldPlayOnHover: false,
  shouldPlayMetronomeSound: false,
  shouldShowClusterTags: true,
};

const settings = (state = initialState, action) => {
  switch (action.type) {
    case TOGGLE_PLAY_ON_HOVER: {
      return Object.assign({}, state, {
        shouldPlayOnHover: !state.shouldPlayOnHover,
      });
    }
    case SET_SHOULD_PLAY_ON_HOVER: {
      return Object.assign({}, state, {
        shouldPlayOnHover: action.shouldPlayOnHover,
      });
    }
    case TOGGLE_METRONOME_SOUND: {
      return Object.assign({}, state, {
        shouldPlayMetronomeSound: !state.shouldPlayMetronomeSound,
      });
    }
    case TOGGLE_CLUSTER_TAGS: {
      return Object.assign({}, state, {
        shouldShowClusterTags: !state.shouldShowClusterTags,
      });
    }
    default:
      return state;
  }
};

export default storable(settings);
<|endoftext|>


<commit_before>/**
* Editable Popover
* ---------------------
* requires bootstrap-popover.js
*/
(function ($) {

    //extend methods
    $.extend($.fn.editableContainer.Constructor.prototype, {
        containerName: 'popover',
        innerCss: '.popover-content p',

        initContainer: function(){
            $.extend(this.containerOptions, {
                trigger: 'manual',
                selector: false,
                content: ' '
            });
            this.call(this.containerOptions);
        },

        setContainerOption: function(key, value) {
            this.container().options[key] = value;
        },

        /**
        * move popover to new position. This function mainly copied from bootstrap-popover.
        */
        /*jshint laxcomma: true*/
        setPosition: function () {

            (function() {
                var $tip = this.tip()
                , inside
                , pos
                , actualWidth
                , actualHeight
                , placement
                , tp;

                placement = typeof this.options.placement === 'function' ?
                this.options.placement.call(this, $tip[0], this.$element[0]) :
                this.options.placement;

                inside = /in/.test(placement);

                $tip
              //  .detach()
              //vitalets: remove any placement class because otherwise they dont influence on re-positioning of visible popover
                .removeClass('top right bottom left')
                .css({ top: 0, left: 0, display: 'block' });
              //  .insertAfter(this.$element);

                pos = this.getPosition(inside);

                actualWidth = $tip[0].offsetWidth;
                actualHeight = $tip[0].offsetHeight;

                switch (inside ? placement.split(' ')[1] : placement) {
                    case 'bottom':
                        tp = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2};
                        break;
                    case 'top':
                        tp = {top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2};
                        break;
                    case 'left':
                        tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth};
                        break;
                    case 'right':
                        tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width};
                        break;
                }

                $tip
                .offset(tp)
                .addClass(placement)
                .addClass('in');

            }).call(this.container());
          /*jshint laxcomma: false*/
        }
    });

    //defaults
    /*
    $.fn.editableContainer.defaults = $.extend({}, $.fn.popover.defaults, $.fn.editableContainer.defaults, {

    });
    */

}(window.jQuery));<commit_msg>support for bootstrap 222, fix #43<commit_after>/**
* Editable Popover
* ---------------------
* requires bootstrap-popover.js
*/
(function ($) {

    //extend methods
    $.extend($.fn.editableContainer.Constructor.prototype, {
        containerName: 'popover',
        //for compatibility with bootstrap <= 2.2.1 (content inserted into <p> instead of directly .popover-content)
        innerCss: $($.fn.popover.defaults.template).find('p').length ? '.popover-content p' : '.popover-content',

        initContainer: function(){
            $.extend(this.containerOptions, {
                trigger: 'manual',
                selector: false,
                content: ' '
            });
            this.call(this.containerOptions);
        },

        setContainerOption: function(key, value) {
            this.container().options[key] = value;
        },

        /**
        * move popover to new position. This function mainly copied from bootstrap-popover.
        */
        /*jshint laxcomma: true*/
        setPosition: function () {

            (function() {
                var $tip = this.tip()
                , inside
                , pos
                , actualWidth
                , actualHeight
                , placement
                , tp;

                placement = typeof this.options.placement === 'function' ?
                this.options.placement.call(this, $tip[0], this.$element[0]) :
                this.options.placement;

                inside = /in/.test(placement);

                $tip
              //  .detach()
              //vitalets: remove any placement class because otherwise they dont influence on re-positioning of visible popover
                .removeClass('top right bottom left')
                .css({ top: 0, left: 0, display: 'block' });
              //  .insertAfter(this.$element);

                pos = this.getPosition(inside);

                actualWidth = $tip[0].offsetWidth;
                actualHeight = $tip[0].offsetHeight;

                switch (inside ? placement.split(' ')[1] : placement) {
                    case 'bottom':
                        tp = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2};
                        break;
                    case 'top':
                        tp = {top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2};
                        break;
                    case 'left':
                        tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth};
                        break;
                    case 'right':
                        tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width};
                        break;
                }

                $tip
                .offset(tp)
                .addClass(placement)
                .addClass('in');

            }).call(this.container());
          /*jshint laxcomma: false*/
        }
    });

    //defaults
    /*
    $.fn.editableContainer.defaults = $.extend({}, $.fn.popover.defaults, $.fn.editableContainer.defaults, {

    });
    */

}(window.jQuery));<|endoftext|>


<commit_before>describe("animate", function() {
    var box;

    before(function() {
        bootbox.animate(true);
    });

    after(function() {
        $(".bootbox")
        .modal('hide')
        .remove();
    });

    describe("when enabled", function() {
        before(function() {
            box = bootbox.dialog("foo");
        });

        it("should apply the correct class to the modal", function() {
            assert.isTrue(box.hasClass("fade"));
        });
    });

    describe("when disabled but passed as an option", function() {
        before(function() {
            bootbox.animate(false);
            box = bootbox.dialog("foo", [], {"animate": true});
        });

        it("should apply the correct class to the modal", function() {
            assert.isTrue(box.hasClass("fade"));
        });
    });
});
<commit_msg>rejig animation tests a bit<commit_after>describe("animate", function() {
    var box;

    before(function() {
        bootbox.animate(false);
    });

    after(function() {
        $(".bootbox")
        .modal('hide')
        .remove();
    });

    describe("when disabled", function() {
        before(function() {
            box = bootbox.dialog("foo");
        });

        it("should not apply the fade class to the modal", function() {
            assert.isFalse(box.hasClass("fade"));
        });

        describe("but when passed as an option", function() {
            before(function() {
                box = bootbox.dialog("foo", [], {"animate": true});
            });

            it("should apply the fade class to the modal", function() {
                assert.isTrue(box.hasClass("fade"));
            });
        });

    });

    describe("when enabled", function() {
        before(function() {
            bootbox.animate(true);
            box = bootbox.dialog("foo");
        });

        it("should apply the fase class to the modal", function() {
            assert.isTrue(box.hasClass("fade"));
        });
    });

});
<|endoftext|>


<commit_before>"use strict";

var EventListener = require('fbjs/lib/EventListener');
var ReactDOM = require('react-dom');

module.exports = {
    EventListener,
    ownerDocument,
    isNodeInRoot,
    listen

}
/**
 * listen
 */
function listen(node, event, func) {
    return EventListener.listen(ownerDocument(node), event, func);
}
/**
 * Get elements owner document
 *
 * @param {ReactComponent|HTMLElement} componentOrElement
 * @returns {HTMLElement}
 */
function ownerDocument(componentOrElement) {
    var elem = ReactDOM.findDOMNode(componentOrElement);
    return elem && elem.ownerDocument || document;
}
/**
 * Checks whether a node is within
 * a root nodes tree
 *
 * @param {DOMElement} node
 * @param {DOMElement} root
 * @returns {boolean}
 */
function isNodeInRoot(node, root) {
    node = ReactDOM.findDOMNode(node), root = ReactDOM.findDOMNode(root);
    _isNodeInRoot(node, root);
}
function _isNodeInRoot(node, root){
    while (node) {
        if (node === root) {
            return true;
        }
        node = node.parentNode;
    }

    return false;
}<commit_msg>Fix click outside<commit_after>"use strict";

var EventListener = require('fbjs/lib/EventListener');
var ReactDOM = require('react-dom');

module.exports = {
    EventListener,
    ownerDocument,
    isNodeInRoot,
    listen

}
/**
 * listen
 */
function listen(node, event, func) {
    return EventListener.listen(ownerDocument(node), event, func);
}
/**
 * Get elements owner document
 *
 * @param {ReactComponent|HTMLElement} componentOrElement
 * @returns {HTMLElement}
 */
function ownerDocument(componentOrElement) {
    var elem = ReactDOM.findDOMNode(componentOrElement);
    return elem && elem.ownerDocument || document;
}
/**
 * Checks whether a node is within
 * a root nodes tree
 *
 * @param {DOMElement} node
 * @param {DOMElement} root
 * @returns {boolean}
 */
function isNodeInRoot(node, root) {
    node = ReactDOM.findDOMNode(node), root = ReactDOM.findDOMNode(root);
    return _isNodeInRoot(node, root);
}
function _isNodeInRoot(node, root){
    while (node) {
        if (node === root) {
            return true;
        }
        node = node.parentNode;
    }

    return false;
}<|endoftext|>


<commit_before>// Design Basic Game Solo Challenge

// This is a solo challenge

// Your mission description:
// Overall mission: Create a fast version of the card game WAR, I'm calling Blitzkrieg WAR.
// Goals: Collect the most cards
// Characters: Player 1 and Player 2
// Objects: player1, player2, cardsInHand, cardsWon
// Functions: dealCards, flipCards, compareCards,

// Pseudocode
// Deal 26 randomly shuffled cards to both Player 1 and Player 2
// Flip top card from each player's hand
// Compare cards played
// IF cards played are the same, declare a WAR
// Add cards to winning player's discard pile
// IF cards played are the same

// Initial Code

// var deck = new PlayerDeck();

// function PlayerDeck() {
//   this.cards = [];
//   var suits = ['C','D','H','S'];

//   for(var i = 2; i < 15; i++) {
//     for (var j = 0; j < suits.length; j++) {
//       this.cards.push(i + '_' + suits[j]);
//     }
//   };

//   var i = this.cards.length, j, temp;

//   while (--i > 0) {
//     j = Math.floor(Math.random() * i);
//     temp = this.cards[j];
//     this.cards[j] = this.cards[i];
//     this.cards[i] = temp;
//   };
//   this.player1Deck = this.cards.slice(0,26);
//   this.player2Deck = this.cards.slice(26);
// }

// function playHand(temp) {
//   change();
//   var player1Won = [];
//   var player2Won = [];
//   var player1Hand = temp.player1Deck.shift();
//   var player2Hand = temp.player2Deck.shift();
//   console.log(player1Hand);
//   console.log(player2Hand);
//   var player1Value = parseInt(player1Hand.split('_'));
//   var player2Value = parseInt(player2Hand.split('_'));
//   console.log(player1Value);
//   console.log(player2Value);
//   if(player1Value > player2Value) {
//     console.log("Player 1 Won this hand!");
//     winner('win1');
//   } else if(player1Value < player2Value) {
//     console.log("Player 2 Won this hand!");
//     winner('win2');
//   } else {
//     winner('tie');
//   };
//   toggleVisibility('player1', player1Hand);
//   toggleVisibility('player2', player2Hand);
// }

// function toggleVisibility(player, value) {
//   var commandStr = document.getElementById(player)
//   commandStr += commandStr.src = "../imgs/war/" + value + ".svg";
// }

// function winner(winner) {
//   document.getElementById(winner).style.display = "block";
// }

// function change()
// {
//     var elem = document.getElementById('button');
//     if (elem.value=="Deal") elem.value = "Play Again?";
// }

// Refactored Code
function startGame() {
  document.getElementById('welcome').style.display = "none";
}

function newGame() {
  location.reload();
}

var deck = new PlayerDeck();

var player1 = {
  score: 0,
  name: 'You',
}

var player2 = {
  score: 0,
  name: 'Atticus',
}

function PlayerDeck() {
  this.cards = [];
  var suits = ['C','D','H','S'];

  for(var i = 2; i < 15; i++) {
    for (var j = 0; j < suits.length; j++) {
      this.cards.push(i + '_' + suits[j]);
    }
  };

  var i = this.cards.length, j, temp;

  while (--i > 0) {
    j = Math.floor(Math.random() * i);
    temp = this.cards[j];
    this.cards[j] = this.cards[i];
    this.cards[i] = temp;
  };
  this.player1Deck = this.cards.slice(0,26);
  this.player2Deck = this.cards.slice(26);
}

function playHand(temp) {
  var player1Hand = temp.player1Deck.shift();
  var player2Hand = temp.player2Deck.shift();
  var player1Value = parseInt(player1Hand.split('_'));
  var player2Value = parseInt(player2Hand.split('_'));
  if(player1Value > player2Value) {
    player1.score += 2;
    winner('win1');
    showCard('player1', player1Hand);
    showCard('player2', player2Hand);
    gameWon(temp.player1Deck);
  } else if (player1Value < player2Value) {
    player2.score += 2;
    winner('win2');
    showCard('player1', player1Hand);
    showCard('player2', player2Hand);
    gameWon(temp.player1Deck);
  } else {
    winner('war');
    showCard('player1', player1Hand);
    showCard('player2', player2Hand);
    setTimeout(function() {
      war(temp.player1Deck, player1Value, temp.player2Deck, player2Value)
    }, 1000);
   }
}

function showCard(player, value) {
  var commandStr = document.getElementById(player)
  commandStr += commandStr.src = "../imgs/war/" + value + ".svg";
}

function war(hand1, value1, hand2, value2) {
  var war1Value = value1;
  var war2Value = value2;
  if(hand1.length > 4) {
    while(war1Value === war2Value) {
      for(var i = 0; i < 4; i++) {
        var warHand1 = hand1.shift();
      }
      for(var i = 0; i < 4; i++) {
        var warHand2 = hand2.shift();
      }
      war1Value = parseInt(warHand1.split('_'));
      war2Value = parseInt(warHand2.split('_'));
      if(war1Value > war2Value) {
        player1.score += 10;
        winner('win1');
        showCard('player1', warHand1);
        showCard('player2', warHand2);
      } else if (war1Value < war2Value) {
        player2.score += 10;
        winner('win2');
        showCard('player1', warHand1);
        showCard('player2', warHand2);
      }
    }
  } else {
    gameWon(hand1);
  }
}

function winner(object) {
  switch (object) {
    case 'win1':
      document.getElementById('win1').style.display = "block";
      document.getElementById('win2').style.display = "none";
      document.getElementById('war').style.display = "none";
      addRow('player1-wins', player1.score);
      break;
    case 'win2':
      document.getElementById('win1').style.display = "none";
      document.getElementById('win2').style.display = "block";
      document.getElementById('war').style.display = "none";
      addRow('player2-wins', player2.score);
      break;
      case 'war':
      document.getElementById('win1').style.display = "none";
      document.getElementById('win2').style.display = "none";
      document.getElementById('war').style.display = "block";
      break;
    default:
      document.getElementById('win1').style.display = "none";
      document.getElementById('win2').style.display = "none";
      document.getElementById('war').style.display = "none";
  }
}

function gameWon(length) {
  var test = true;
  switch (test) {
    case length.length === 0 && player1.score > player2.score:
    document.getElementById('card-back1').style.display = "none";
    document.getElementById('card-back2').style.display = "none";
    winner(1);
    displayWinner('player1');
    break;
    case length.length === 0 && player1.score < player2.score:
    document.getElementById('card-back1').style.display = "none";
    document.getElementById('card-back2').style.display = "none";
    winner(2);
    displayWinner('player2');
    break;
    case length.length === 0 && player1.score === player2.score:
    document.getElementById('card-back1').style.display = "none";
    document.getElementById('card-back2').style.display = "none";
    winner(3);
    displayWinner('tied');
    break;
    default:
  }
}

function addRow(player, score) {
  var playerId;
  if(player === 'player1-wins') {
    playerId = player1.name;
  } else {
    playerId = player2.name;
  }
    if (score !== 2) {
      var test = document.getElementById(player);
      test.innerHTML = playerId + ' won ' + score + ' cards!';
    } else {
      var h2 = document.createElement('h2');
      h2.id = player;
      h2.innerHTML = playerId + ' won 2 cards!';
      document.getElementById('display').appendChild(h2);
    }
}

function displayWinner(winner) {
  document.getElementById('winner').src = "../imgs/war/" + winner + ".png";
  document.getElementById('winner').style.display = "block";
  document.getElementById('winner-btn').style.display = "block";
}

// Reflection
/*
    What was it like to approach the problem from the perspective of JavaScript? Did you approach the problem differently?
    I don't think that I my approach was any different because this was JavaScript. I felt that my biggest issues was going too far down the rabbit hole in trying to get the game to work the way I intended. Each time I thought that I had figured one thing out and could do more, I quickly realized that it created 10 different issues I hadn't counted on.

    What did you learn about iterating over arrays in JavaScript?
    That it is not that much different from Ruby and is pretty straight forward.

    What was different about solving this problem in JavaScript?
    I think the biggest difference I had was the shear scope of what the project ended up becoming. Prior to this, I hadn't really down anything this large that wasn't primarily HTML and CSS.

    What built-in methods did you find to incorporate in your refactored solution?
    I'm sure that there are several that I could have used, but I spent so much time trying to just get it to work that I really didn't bother refactoring too much.

*/

<commit_msg>Add correct reflection answers to game.js file<commit_after>// Design Basic Game Solo Challenge

// This is a solo challenge

// Your mission description:
// Overall mission: Create a fast version of the card game WAR, I'm calling Blitzkrieg WAR.
// Goals: Collect the most cards
// Characters: Player 1 and Player 2
// Objects: player1, player2, cardsInHand, cardsWon
// Functions: dealCards, flipCards, compareCards,

// Pseudocode
// Deal 26 randomly shuffled cards to both Player 1 and Player 2
// Flip top card from each player's hand
// Compare cards played
// IF cards played are the same, declare a WAR
// Add cards to winning player's discard pile
// IF cards played are the same

// Initial Code

// var deck = new PlayerDeck();

// function PlayerDeck() {
//   this.cards = [];
//   var suits = ['C','D','H','S'];

//   for(var i = 2; i < 15; i++) {
//     for (var j = 0; j < suits.length; j++) {
//       this.cards.push(i + '_' + suits[j]);
//     }
//   };

//   var i = this.cards.length, j, temp;

//   while (--i > 0) {
//     j = Math.floor(Math.random() * i);
//     temp = this.cards[j];
//     this.cards[j] = this.cards[i];
//     this.cards[i] = temp;
//   };
//   this.player1Deck = this.cards.slice(0,26);
//   this.player2Deck = this.cards.slice(26);
// }

// function playHand(temp) {
//   change();
//   var player1Won = [];
//   var player2Won = [];
//   var player1Hand = temp.player1Deck.shift();
//   var player2Hand = temp.player2Deck.shift();
//   console.log(player1Hand);
//   console.log(player2Hand);
//   var player1Value = parseInt(player1Hand.split('_'));
//   var player2Value = parseInt(player2Hand.split('_'));
//   console.log(player1Value);
//   console.log(player2Value);
//   if(player1Value > player2Value) {
//     console.log("Player 1 Won this hand!");
//     winner('win1');
//   } else if(player1Value < player2Value) {
//     console.log("Player 2 Won this hand!");
//     winner('win2');
//   } else {
//     winner('tie');
//   };
//   toggleVisibility('player1', player1Hand);
//   toggleVisibility('player2', player2Hand);
// }

// function toggleVisibility(player, value) {
//   var commandStr = document.getElementById(player)
//   commandStr += commandStr.src = "../imgs/war/" + value + ".svg";
// }

// function winner(winner) {
//   document.getElementById(winner).style.display = "block";
// }

// function change()
// {
//     var elem = document.getElementById('button');
//     if (elem.value=="Deal") elem.value = "Play Again?";
// }

// Refactored Code
function startGame() {
  document.getElementById('welcome').style.display = "none";
}

function newGame() {
  location.reload();
}

var deck = new PlayerDeck();

var player1 = {
  score: 0,
  name: 'You',
}

var player2 = {
  score: 0,
  name: 'Atticus',
}

function PlayerDeck() {
  this.cards = [];
  var suits = ['C','D','H','S'];

  for(var i = 2; i < 15; i++) {
    for (var j = 0; j < suits.length; j++) {
      this.cards.push(i + '_' + suits[j]);
    }
  };

  var i = this.cards.length, j, temp;

  while (--i > 0) {
    j = Math.floor(Math.random() * i);
    temp = this.cards[j];
    this.cards[j] = this.cards[i];
    this.cards[i] = temp;
  };
  this.player1Deck = this.cards.slice(0,26);
  this.player2Deck = this.cards.slice(26);
}

function playHand(temp) {
  var player1Hand = temp.player1Deck.shift();
  var player2Hand = temp.player2Deck.shift();
  var player1Value = parseInt(player1Hand.split('_'));
  var player2Value = parseInt(player2Hand.split('_'));
  if(player1Value > player2Value) {
    player1.score += 2;
    winner('win1');
    showCard('player1', player1Hand);
    showCard('player2', player2Hand);
    gameWon(temp.player1Deck);
  } else if (player1Value < player2Value) {
    player2.score += 2;
    winner('win2');
    showCard('player1', player1Hand);
    showCard('player2', player2Hand);
    gameWon(temp.player1Deck);
  } else {
    winner('war');
    showCard('player1', player1Hand);
    showCard('player2', player2Hand);
    setTimeout(function() {
      war(temp.player1Deck, player1Value, temp.player2Deck, player2Value)
    }, 1000);
   }
}

function showCard(player, value) {
  var commandStr = document.getElementById(player)
  commandStr += commandStr.src = "../imgs/war/" + value + ".svg";
}

function war(hand1, value1, hand2, value2) {
  var war1Value = value1;
  var war2Value = value2;
  if(hand1.length > 4) {
    while(war1Value === war2Value) {
      for(var i = 0; i < 4; i++) {
        var warHand1 = hand1.shift();
      }
      for(var i = 0; i < 4; i++) {
        var warHand2 = hand2.shift();
      }
      war1Value = parseInt(warHand1.split('_'));
      war2Value = parseInt(warHand2.split('_'));
      if(war1Value > war2Value) {
        player1.score += 10;
        winner('win1');
        showCard('player1', warHand1);
        showCard('player2', warHand2);
      } else if (war1Value < war2Value) {
        player2.score += 10;
        winner('win2');
        showCard('player1', warHand1);
        showCard('player2', warHand2);
      }
    }
  } else {
    gameWon(hand1);
  }
}

function winner(object) {
  switch (object) {
    case 'win1':
      document.getElementById('win1').style.display = "block";
      document.getElementById('win2').style.display = "none";
      document.getElementById('war').style.display = "none";
      addRow('player1-wins', player1.score);
      break;
    case 'win2':
      document.getElementById('win1').style.display = "none";
      document.getElementById('win2').style.display = "block";
      document.getElementById('war').style.display = "none";
      addRow('player2-wins', player2.score);
      break;
      case 'war':
      document.getElementById('win1').style.display = "none";
      document.getElementById('win2').style.display = "none";
      document.getElementById('war').style.display = "block";
      break;
    default:
      document.getElementById('win1').style.display = "none";
      document.getElementById('win2').style.display = "none";
      document.getElementById('war').style.display = "none";
  }
}

function gameWon(length) {
  var test = true;
  switch (test) {
    case length.length === 0 && player1.score > player2.score:
    document.getElementById('card-back1').style.display = "none";
    document.getElementById('card-back2').style.display = "none";
    winner(1);
    displayWinner('player1');
    break;
    case length.length === 0 && player1.score < player2.score:
    document.getElementById('card-back1').style.display = "none";
    document.getElementById('card-back2').style.display = "none";
    winner(2);
    displayWinner('player2');
    break;
    case length.length === 0 && player1.score === player2.score:
    document.getElementById('card-back1').style.display = "none";
    document.getElementById('card-back2').style.display = "none";
    winner(3);
    displayWinner('tied');
    break;
    default:
  }
}

function addRow(player, score) {
  var playerId;
  if(player === 'player1-wins') {
    playerId = player1.name;
  } else {
    playerId = player2.name;
  }
    if (score !== 2) {
      var test = document.getElementById(player);
      test.innerHTML = playerId + ' won ' + score + ' cards!';
    } else {
      var h2 = document.createElement('h2');
      h2.id = player;
      h2.innerHTML = playerId + ' won 2 cards!';
      document.getElementById('display').appendChild(h2);
    }
}

function displayWinner(winner) {
  document.getElementById('winner').src = "../imgs/war/" + winner + ".png";
  document.getElementById('winner').style.display = "block";
  document.getElementById('winner-btn').style.display = "block";
}

// Reflection
/*
    What was the most difficult part of this challenge?
    I felt that my biggest issues was going too far down the rabbit hole in trying to get the game to work the way I intended. Each time I thought that I had figured one thing out and could do more, I quickly realized that it created 10 different issues I hadn't counted on. This is an example of bitting off more than I could chew, but I learned a lot!

    What did you learn about creating objects and functions that interact with one another?
    It was differently beneficial, again the biggest issue was that I was trying so hard to just get it to work I didn't really spend too much time refactoring. I'm sure I will go back over this and try and clean it up later.

    Did you learn about any new built-in methods you could use in your refactored solution? If so, what were they and how do they work?
    I'm sure that there are several that I could have used, but I spent so much time trying to just get it to work that I really didn't bother refactoring too much.

    How can you access and manipulate properties of objects?
    You can access and manipulate the properties of objects by calling the property and either directly assigning a new value or by passing a new value to it from another function.

*/

<|endoftext|>


<commit_before>const {BrowserWindow} = require('electron')
const CssInjector = require('../js/css-injector');

class RadioController {

  constructor() {
    this.init();
  }

  init() {
    this.window = new BrowserWindow({
      width: 1000,
      height: 470,
      show: false,
      frame: true,
      autoHideMenuBar: true,
      webPreferences: {
        plugins: true
      },
    });

    this.window.on('close', (e) => {
      if (this.window.isVisible()) {
        e.preventDefault();
        this.window.hide();
      }
    });

    this.window.loadURL('http://www.xiami.com/radio');

    this.window.webContents.on('dom-ready', () => {
      this.window.webContents.insertCSS(CssInjector.radio);
      this.show();
    });
  }

  show() {
    if (this.window.isMinimized()) this.window.restore()
    this.window.focus()
  }
}

module.exports = RadioController;<commit_msg>chore(versioning): replace the deprecated methods<commit_after>const {BrowserWindow} = require('electron')
const CssInjector = require('../js/css-injector');

class RadioController {

  constructor() {
    this.init();
  }

  init() {
    this.window = new BrowserWindow({
      width: 1000,
      height: 470,
      show: false,
      frame: true,
      autoHideMenuBar: true,
      webPreferences: {
        plugins: true
      },
    });

    this.window.on('close', (e) => {
      if (this.window.isVisible()) {
        e.preventDefault();
        this.window.hide();
      }
    });

    this.window.loadURL('http://www.xiami.com/radio');

    this.window.webContents.on('dom-ready', () => {
      this.window.webContents.insertCSS(CssInjector.radio);
      this.show();
    });
  }

  show() {
    this.window.show();
    this.window.focus();
  }
}

module.exports = RadioController;<|endoftext|>


<commit_before>var EZ3 = function() {
};

EZ3 = new EZ3();

EZ3.extends = function(destination, source) {
  var k;

  for (k in source)
    if (source.hasOwnProperty(k))
      destination[k] = source[k];
};

EZ3.toFileName = function(url) {
  return url.split('/').pop();
};

EZ3.toFileExtension = function(url) {
  return url.split('/').pop().split('.').pop();
};

EZ3.toBaseUrl = function(url) {
  var tokens = url.split('/');

  return url.substr(0, url.length - tokens[tokens.length - 1].length);
};
<commit_msg>Updated<commit_after>var EZ3 = function() {};

EZ3 = new EZ3();

EZ3.extends = function(destination, source) {
  var k;

  for (k in source)
    destination[k] = source[k];
};

EZ3.toFileName = function(url) {
  return url.split('/').pop();
};

EZ3.toFileExtension = function(url) {
  return url.split('/').pop().split('.').pop();
};

EZ3.toBaseUrl = function(url) {
  var tokens = url.split('/');

  return url.substr(0, url.length - tokens[tokens.length - 1].length);
};
<|endoftext|>


<commit_before>// Design Basic Game Solo Challenge

// This is a solo challenge

// Your mission description: Solo battle ships
// Overall mission: Find and sink 2 battle ships
// Goals: guess coordinstes of ships
// Characters: player and ships
// Objects: 2 ships of length 2 and 3
// Functions: Set up board and place ships randomly
//  Take input from user and return hit if ship is at that coordinate and miss if not.
//  Print game bord to screen.

// Pseudocode
// 1. Create game borad.  Borad is made up of 7 arrays each containing 7 0s.
// 2. Create function that prints board to screen as a 7x7 grid with the letters A-G allong the left hand side and the number 1-7 along the top.
// 3. Define 2 ship objects one with 2 coordinate perameters and the other with 2.  They should also each have a hit counter that starts at 0 and a 'sunk?'
//     Perameter that starts at false and becomes true when hit count equals ship length.
// 4. To place ships randomly first select a random number between 1 and 2.
//    1 indicates a horizontal ship 2 indicates a vertical ship.
//      If 1 select a random number 'n' between 1 and 7-ship.length. for a ship of length 3 the ships horizontal coordinates will be (n,n+1,n+2)
//      Now select a random letter 'L' between A and G and assign the coordinates L,n L,n+1 and n+2 to the ship object.
//
//      If 2 follow same process but with consecutive letters and a single number.
// 5. Define a function 'guess' that takes a coordinate input and returns 'Hit' if the coordinate matches that of either ship object and "Miss" if not.
//    if hit occurs the hit occures +1 to hit count if 'sunk?' then eqauls true print "You sunk a battle ship!!" to the screen.
//    Function should then modify the game bord to replace misses with 'M' and hits with 'X' then print the board.
//    The guess function should repeat until both ships are sunk.

// Initial Code

var board = {
	n:["O",1,2,3,4,5,6,7],
	a:["A",0,0,0,0,0,0,0],
	b:["B",0,0,0,0,0,0,0],
	c:["C",0,0,0,0,0,0,0],
	d:["D",0,0,0,0,0,0,0],
	e:["E",0,0,0,0,0,0,0],
	f:["F",0,0,0,0,0,0,0],
	g:["G",0,0,0,0,0,0,0],

}

var small_ship = {
<<<<<<< HEAD
	pos:[["a",1],["a",2]],
=======
	pos:[["A",1],["B",2]],
>>>>>>> ce557a49cd2dc9a19e30879cbef9c7cfcd0b9571
	hit_count:0,
	sunk: false,
}

var big_ship = {
<<<<<<< HEAD
	pos:[["b",3],["c",3],["d",3]],
	hit_count: 0,
	sunk: false,
=======
	pos:[['B',3],['C',3],['D',3]],
	hit_count:0,
	sunk:false,
>>>>>>> ce557a49cd2dc9a19e30879cbef9c7cfcd0b9571
}

function print_board(board){
  console.log(board)
}

print_board(board)

function guess(guess){
<<<<<<< HEAD

	if ((guess[0] == small_ship["pos"][0][0] && guess[1] == small_ship["pos"][0][1]) || (guess[0] == small_ship["pos"][1][0] && guess[1] == small_ship["pos"][1][1])){
=======
	console.log(small_ship["pos"])
	if (small_ship["pos"].includes(guess));{
>>>>>>> ce557a49cd2dc9a19e30879cbef9c7cfcd0b9571
		console.log("Hit!");
		small_ship["hit_count"] ++;
	    board[guess[0]][guess[1]] = "X";
	    print_board(board)
      if (small_ship["hit_count"] == 2){
    	small_ship["sunk"] = true;
    	console.log("You sunk a battle ship!!")}
    }
    else if ((guess[0] == big_ship["pos"][0][0] && guess[1] == big_ship["pos"][0][1]) || (guess[0] == big_ship["pos"][1][0] && guess[1] == big_ship["pos"][1][1])
    	|| (guess[0] == big_ship["pos"][2][0] && guess[1] == big_ship["pos"][2][1])){
    	console.log("Hit!");
		big_ship["hit_count"] ++;
	    board[guess[0]][guess[1]] = "X";
	    print_board(board)
	    if (big_ship["hit_count"] == 3){
	    	big_ship["sunk"] = true
	    	console.log("You sunk a battle ship!!")
	    }
    }
    else {
    	console.log("Miss!")
    	board[guess[0]][guess[1]] = "M";
	    print_board(board)
    }

    if (small_ship.sunk == true && big_ship.sunk == true)
    	console.log("You Win!!!!")

}

<<<<<<< HEAD
guess(["a",1])
guess(["a",2])
guess(["e",6])
guess(["b",3])
guess(["c",3])
guess(["d",3])
=======
guess(["A",1])
guess(["B",2])

>>>>>>> ce557a49cd2dc9a19e30879cbef9c7cfcd0b9571

// Refactored Code

// Reflection
//What was the most difficult part of this challenge?
//    Every part of this challenge was difficult for me. You'll notice that the solution is much more simple than what I envisoned at the Pseudocode stage.  I set out to
//    create somthing that I thought would be relatively simple but ended up hitting walls at every stage. Firstly dispite hours of experimenting and researching I could not
//    get javascript to agree that two arrays were equal which is why I ended up with the extemly cumbersome if statements that compare each individual element of 'guess'
//    with each element of 'pos'.  I then spent an hour trying to figure out why I was getting "unexpected token 'else'" only to discover it was because i'd inserted an extra ;.
//    I then spent a very long time researching how to get javascript to accept user input from the command line but could not make it work.  Eventually i deceded that although it was
//    not what I wanted the code I have here does at least work to some degree and I'd already spent FAR to long on this problem.

// What did you learn about creating objects and functions that interact with one another?

//   At this point i'm really not sure.

// Did you learn about any new built-in methods you could use in your refactored solution? If so, what were they and how do they work?

//   I tryied to use .includes to see if 'pos' included guess but I was repeatedly told that .includes is not a function.

// How can you access and manipulate properties of objects?

//   Properties can be accesses by object_name["property_name"] or object_name.property_name.
//
//
//
//  I hope to come back to this exercise and complete my game at a later stage but for now I just can't take any more JavaScript.
//
//
//<commit_msg>Corrects some crazy stuff git did to my code<commit_after>// Design Basic Game Solo Challenge

// This is a solo challenge

// Your mission description: Solo battle ships
// Overall mission: Find and sink 2 battle ships
// Goals: guess coordinstes of ships
// Characters: player and ships
// Objects: 2 ships of length 2 and 3
// Functions: Set up board and place ships randomly
//  Take input from user and return hit if ship is at that coordinate and miss if not.
//  Print game bord to screen.

// Pseudocode
// 1. Create game borad.  Borad is made up of 7 arrays each containing 7 0s.
// 2. Create function that prints board to screen as a 7x7 grid with the letters A-G allong the left hand side and the number 1-7 along the top.
// 3. Define 2 ship objects one with 2 coordinate perameters and the other with 2.  They should also each have a hit counter that starts at 0 and a 'sunk?'
//     Perameter that starts at false and becomes true when hit count equals ship length.
// 4. To place ships randomly first select a random number between 1 and 2.
//    1 indicates a horizontal ship 2 indicates a vertical ship.
//      If 1 select a random number 'n' between 1 and 7-ship.length. for a ship of length 3 the ships horizontal coordinates will be (n,n+1,n+2)
//      Now select a random letter 'L' between A and G and assign the coordinates L,n L,n+1 and n+2 to the ship object.
//
//      If 2 follow same process but with consecutive letters and a single number.
// 5. Define a function 'guess' that takes a coordinate input and returns 'Hit' if the coordinate matches that of either ship object and "Miss" if not.
//    if hit occurs the hit occures +1 to hit count if 'sunk?' then eqauls true print "You sunk a battle ship!!" to the screen.
//    Function should then modify the game bord to replace misses with 'M' and hits with 'X' then print the board.
//    The guess function should repeat until both ships are sunk.

// Initial Code

var board = {
	n:["O",1,2,3,4,5,6,7],
	a:["A",0,0,0,0,0,0,0],
	b:["B",0,0,0,0,0,0,0],
	c:["C",0,0,0,0,0,0,0],
	d:["D",0,0,0,0,0,0,0],
	e:["E",0,0,0,0,0,0,0],
	f:["F",0,0,0,0,0,0,0],
	g:["G",0,0,0,0,0,0,0],

}

var small_ship = {

	pos:[["a",1],["a",2]],

	hit_count:0,
	sunk: false,
}

var big_ship = {

	pos:[["b",3],["c",3],["d",3]],
	hit_count: 0,
	sunk: false,

}

function print_board(board){
  console.log(board)
}

print_board(board)

function guess(guess){

	if ((guess[0] == small_ship["pos"][0][0] && guess[1] == small_ship["pos"][0][1]) || (guess[0] == small_ship["pos"][1][0] && guess[1] == small_ship["pos"][1][1])){
	    console.log("Hit!");
		small_ship["hit_count"] ++;
	    board[guess[0]][guess[1]] = "X";
	    print_board(board)
      if (small_ship["hit_count"] == 2){
    	small_ship["sunk"] = true;
    	console.log("You sunk a battle ship!!")}
    }
    else if ((guess[0] == big_ship["pos"][0][0] && guess[1] == big_ship["pos"][0][1]) || (guess[0] == big_ship["pos"][1][0] && guess[1] == big_ship["pos"][1][1])
    	|| (guess[0] == big_ship["pos"][2][0] && guess[1] == big_ship["pos"][2][1])){
    	console.log("Hit!");
		big_ship["hit_count"] ++;
	    board[guess[0]][guess[1]] = "X";
	    print_board(board)
	    if (big_ship["hit_count"] == 3){
	    	big_ship["sunk"] = true
	    	console.log("You sunk a battle ship!!")
	    }
    }
    else {
     	console.log("Miss!")
    	board[guess[0]][guess[1]] = "M";
	    print_board(board)
    }

    if (small_ship.sunk == true && big_ship.sunk == true)
    	console.log("You Win!!!!")

}

guess(["a",1])
guess(["a",2])
guess(["e",6])
guess(["b",3])
guess(["c",3])
guess(["d",3])

// Refactored Code

// Reflection
//What was the most difficult part of this challenge?
//    Every part of this challenge was difficult for me. You'll notice that the solution is much more simple than what I envisoned at the Pseudocode stage.  I set out to
//    create somthing that I thought would be relatively simple but ended up hitting walls at every stage. Firstly dispite hours of experimenting and researching I could not
//    get javascript to agree that two arrays were equal which is why I ended up with the extemly cumbersome if statements that compare each individual element of 'guess'
//    with each element of 'pos'.  I then spent an hour trying to figure out why I was getting "unexpected token 'else'" only to discover it was because i'd inserted an extra ;.
//    I then spent a very long time researching how to get javascript to accept user input from the command line but could not make it work.  Eventually i deceded that although it was
//    not what I wanted the code I have here does at least work to some degree and I'd already spent FAR to long on this problem.

// What did you learn about creating objects and functions that interact with one another?

//   At this point i'm really not sure.

// Did you learn about any new built-in methods you could use in your refactored solution? If so, what were they and how do they work?

//   I tryied to use .includes to see if 'pos' included guess but I was repeatedly told that .includes is not a function.

// How can you access and manipulate properties of objects?

//   Properties can be accesses by object_name["property_name"] or object_name.property_name.
//
//
//
//  I hope to come back to this exercise and complete my game at a later stage but for now I just can't take any more JavaScript.
//
//
//<|endoftext|>


<commit_before>// Design Basic Game Solo Challenge

// This is a solo challenge

// Your mission description:
// Overall mission: Donald Trump will decide to fire a contestant based on  their political party or their score in the contestant challange.
// Goals: The Trump objet will contain a function that will determine if contestant properties passes its test. if it does it will say, "congratulations, you are a true American to Donald." else "You're fired!"
// Characters:
//Donald Tump, a Contestant
// Objects:
//Object1:trump
//Object2: constestant
// Functions:
// Function 1:fired function in the donald object: if contestant party is not "rebpublican" or score from the challenge is not above 75 then contestant is fired, else contestant is allowed to join the final stage of the competition.
 // Function2: a function that asks the contestant what their GPS was in college. if range is below 70 group in one category, between 70 and 80 group it, 80 and 90 group it, 90 to 1000 group it.
// Pseudocode
//  Ask for your name in prompt.
//  if no name, then say you're pathetics and your fired
//  if name, then ask in prompt for natioanlity.
//  if nationality is chinese, then hire on the spot.
//  else say its ok and ask your their college gpa
// if gpa over 80 say will consider.
// elsif
//function contestant  (party, gpa, and nationality)
// this.party = party
// this.party = party
//
//
// function trump()
// if ( === "Republian" || gpa.score > 3)
//		console.log("You are a great American!")
// else
//		console.log("You're fired!")
// Initial Code
// create an empty contestant object and give it a job property = to work for donald Trump:
var contestants = []
var anOtherContestant = {};
anOtherContestant.job = "1"
anOtherContestant.name = "2"
anOtherContestant.nationality = "3"
anOtherContestant.party = "4"
anOtherContestant.collegeGpa = "5"

window.onload = function what(){
document.getElementById("onestatus").innerHTML = anOtherContestant.job;
document.getElementById("onepartyz").innerHTML = anOtherContestant.party;
document.getElementById("onenationalityz").innerHTML = anOtherContestant.nationality;
document.getElementById("onenamez").innerHTML = anOtherContestant.name;
document.getElementById("onegpaz").innerHTML = anOtherContestant.collegeGpa;

};

console.log(anOtherContestant);
var contestantYou = {};

contestantYou.job = "Working for donald trump";
document.getElementById("status").innerHTML = contestantYou.job;
// create a property of this object called name based on the answer provided by the prompt (browser only)
contestantYou.name =  prompt("Hello, and Welcome to the Apprentace. Pleast provide you name.");
document.getElementById("namez").innerHTML = contestantYou.name;

if (contestantYou.name === null) {
  console.log('Please provide a valid name');
}

// create a property of this object called party based on the answer provided by the prompt (browser only)
contestantYou.party = prompt("Thanks! Pleast provide your party.");
document.getElementById("partyz").innerHTML = contestantYou.party;

if (contestantYou.party === null) {
  console.log('please provide a valid party');
}

// create a property of this object called collegeGpa based on the answer provided by the prompt (browser only)
contestantYou.collegeGpa = prompt("Thanks! Pleast provide your colleg G.P.A.");
if (contestantYou.collegeGpa === null) {
  console.log('I know its hard, but please provide your college GPA');
}
document.getElementById("gpaz").innerHTML = contestantYou.collegeGpa;

// create a property of this object called nationality based on the answer provided by the prompt (browser only)
contestantYou.nationality = prompt("Thanks! Pleast provide your nationality.");
if (contestantYou.nationality === null) {
  console.log('Come on, everyone has a nationality, choose one.');
};
document.getElementById("nationalityz").innerHTML = contestantYou.nationality;

// print the contestant object (and its properties of course) in the console.
console.log(contestantYou);

document.getElementById("status").innerHTML = contestantYou.job;

function trump(){
  if (contestantYou.nationality === "Chinese" || contestantYou.collegeGpa > 80) {
    console.log("I love your you! You're promoted.");
    contestantYou.job = "PROMOTED!";
    anOtherContestant.job = "Demoted"
    document.getElementById("status").innerHTML = contestantYou.job;
  }
  else {
    contestantYou.job = "FIRED!"
    anOtherContestant.job = "Promoted"
    console.log("I hate you! You're fired!");
    document.getElementById("status").innerHTML = contestantYou.job;
  };

}
trump();

console.log(contestantYou);

// Refactored Code
// create an empty contestant object and give it a job property = to work for donald Trump:
var contestants = []
var anOtherContestant = {};
anOtherContestant.job = "1"
anOtherContestant.namee = "2"
anOtherContestant.nationality = "3"
anOtherContestant.party = "4"
anOtherContestant.collegeGpa = "5"

window.onload = function what(){
document.getElementById("onestatus").innerHTML = anOtherContestant.job;
document.getElementById("onepartyz").innerHTML = anOtherContestant.party;
document.getElementById("onenationalityz").innerHTML = anOtherContestant.nationality;
document.getElementById("onenamez").innerHTML = anOtherContestant.namee;
document.getElementById("onegpaz").innerHTML = anOtherContestant.collegeGpa;

};

console.log(anOtherContestant);
var contestantYou = {};

contestantYou.job = "Working for donald trump";
document.getElementById("status").innerHTML = contestantYou.job;
// create a property of this object called namee (name is a reserved word) based on the answer provided by the prompt (browser only)
contestantYou.namee =  prompt("Hello, and Welcome to the Apprentace. Pleast provide your name.");
document.getElementById("namez").innerHTML = contestantYou.namee;

if (contestantYou.namee === null) {
  console.log('please provide a valid name.');
}

// create a property of this object called party based on the answer provided by the prompt (browser only)
contestantYou.party = prompt("Thanks! Please provide your party.");
document.getElementById("partyz").innerHTML = contestantYou.party;

if (contestantYou.party === null) {
  console.log('Come on you can do this, please provide the party you most associate yourself with');
}

// create a property of this object called collegeGpa based on the answer provided by the prompt (browser only)
contestantYou.collegeGpa = prompt("Thanks! Please provide your colleg G.P.A.");
if (contestantYou.collegeGpa === null) {
  console.log('I know it is hard, but please provide yout true GPA.');
}
document.getElementById("gpaz").innerHTML = contestantYou.collegeGpa;

// create a property of this object called nationality based on the answer provided by the prompt (browser only)
contestantYou.nationality = prompt("Thanks! Please provide your nationality.");
if (contestantYou.nationality === null) {
  console.log('Come on, everyone comes from somewhere, please provide a valid nationality');
};
document.getElementById("nationalityz").innerHTML = contestantYou.nationality;

// print the contestant object (and its properties of course) in the console.
console.log(contestantYou);

document.getElementById("status").innerHTML = contestantYou.job;

function trump(){
  if (contestantYou.nationality === "Chinese" || contestantYou.collegeGpa > 80) {
    console.log("I love your nationality! You're promoted.");
    contestantYou.job = "PROMOTED!";
    anOtherContestant.job = "Demoted"
    document.getElementById("status").innerHTML = contestantYou.job;
  }
  else {
    contestantYou.job = "FIRED!"
    anOtherContestant.job = "Promoted"
    console.log("I hate you! You're fired!");
    document.getElementById("status").innerHTML = contestantYou.job;
  };

}
trump();

console.log(contestantYou);

// Reflection
//What was the most difficult part of this challenge?
// The hardes part of this challenge was getting user input to pop up on the screen. I learned about the document.getElementById("status").innerHTML = ...; method. This take whatever goes after the equal sign to display on the screen. This required one to build an html page as well.
//What did you learn about creating objects and functions that interact with one another?
// I learned that you need a variable to hold a function to access it in another function or if  you want to access a property you must precede it with the parent object name.
//Did you learn about any new built-in methods you could use in your refactored solution? If so, what were they and how do they work? I kind of jumped ahead of the material from this week and leared about the document.getElementById("element").innerHTML = object.property; This method  returns the element that has the ID attribute with the specified value. This method is one of the most common methods in the HTML DOM, and is used almost every time you want to manipulate, or get info from, an element on your document.
//How can you access and manipulate properties of objects?
//There are two ways to access properties of an obect.They are:1.)object.property 2.)object[property]
//
//
//
//
//<commit_msg>game fixes<commit_after>// Design Basic Game Solo Challenge

// This is a solo challenge

// Your mission description:
// Overall mission: Donald Trump will decide to fire a contestant based on  their political party or their score in the contestant challange.
// Goals: The Trump objet will contain a function that will determine if contestant properties passes its test. if it does it will say, "congratulations, you are a true American to Donald." else "You're fired!"
// Characters:
//Donald Tump, a Contestant
// Objects:
//Object1:trump
//Object2: constestant
// Functions:
// Function 1:fired function in the donald object: if contestant party is not "rebpublican" or score from the challenge is not above 75 then contestant is fired, else contestant is allowed to join the final stage of the competition.
 // Function2: a function that asks the contestant what their GPS was in college. if range is below 70 group in one category, between 70 and 80 group it, 80 and 90 group it, 90 to 1000 group it.
// Pseudocode
//  Ask for your name in prompt.
//  if no name, then say you're pathetics and your fired
//  if name, then ask in prompt for natioanlity.
//  if nationality is chinese, then hire on the spot.
//  else say its ok and ask your their college gpa
// if gpa over 80 say will consider.
// elsif
//function contestant  (party, gpa, and nationality)
// this.party = party
// this.party = party
//
//
// function trump()
// if ( === "Republian" || gpa.score > 3)
//		console.log("You are a great American!")
// else
//		console.log("You're fired!")
// Initial Code
// create an empty contestant object and give it a job property = to work for donald Trump:
var contestants = []
var anOtherContestant = {};
anOtherContestant.job =
anOtherContestant.name =
anOtherContestant.nationality =
anOtherContestant.party =
anOtherContestant.collegeGpa =

window.onload = function what(){
document.getElementById("onestatus").innerHTML = anOtherContestant.job;
document.getElementById("onepartyz").innerHTML = anOtherContestant.party;
document.getElementById("onenationalityz").innerHTML = anOtherContestant.nationality;
document.getElementById("onenamez").innerHTML = anOtherContestant.name;
document.getElementById("onegpaz").innerHTML = anOtherContestant.collegeGpa;

};

console.log(anOtherContestant);
var contestantYou = {};

contestantYou.job = "Working for donald trump";
document.getElementById("status").innerHTML = contestantYou.job;
// create a property of this object called name based on the answer provided by the prompt (browser only)
contestantYou.name =  prompt("Hello, and Welcome to the Apprentace. Pleast provide you name.");
document.getElementById("namez").innerHTML = contestantYou.name;

if (contestantYou.name === null) {
  console.log('Please provide a valid name');
}

// create a property of this object called party based on the answer provided by the prompt (browser only)
contestantYou.party = prompt("Thanks! Pleast provide your party.");
document.getElementById("partyz").innerHTML = contestantYou.party;

if (contestantYou.party === null) {
  console.log('please provide a valid party');
}

// create a property of this object called collegeGpa based on the answer provided by the prompt (browser only)
contestantYou.collegeGpa = prompt("Thanks! Pleast provide your colleg G.P.A.");
if (contestantYou.collegeGpa === null) {
  console.log('I know its hard, but please provide your college GPA');
}
document.getElementById("gpaz").innerHTML = contestantYou.collegeGpa;

// create a property of this object called nationality based on the answer provided by the prompt (browser only)
contestantYou.nationality = prompt("Thanks! Pleast provide your nationality.");
if (contestantYou.nationality === null) {
  console.log('Come on, everyone has a nationality, choose one.');
};
document.getElementById("nationalityz").innerHTML = contestantYou.nationality;

// print the contestant object (and its properties of course) in the console.
console.log(contestantYou);

document.getElementById("status").innerHTML = contestantYou.job;

function trump(){
  if (contestantYou.nationality === "Chinese" || contestantYou.collegeGpa > 80) {
    console.log("I love your you! You're promoted.");
    contestantYou.job = "PROMOTED!";
    anOtherContestant.job = "Demoted"
    document.getElementById("status").innerHTML = contestantYou.job;
  }
  else {
    contestantYou.job = "FIRED!"
    anOtherContestant.job = "Promoted"
    console.log("I hate you! You're fired!");
    document.getElementById("status").innerHTML = contestantYou.job;
  };

}
trump();

console.log(contestantYou);

// Refactored Code
// create an empty contestant object and give it a job property = to work for donald Trump:
var contestants = []
var anOtherContestant = {};
anOtherContestant.job = "1"
anOtherContestant.namee = "2"
anOtherContestant.nationality = "3"
anOtherContestant.party = "4"
anOtherContestant.collegeGpa = "5"

window.onload = function what(){
document.getElementById("onestatus").innerHTML = anOtherContestant.job;
document.getElementById("onepartyz").innerHTML = anOtherContestant.party;
document.getElementById("onenationalityz").innerHTML = anOtherContestant.nationality;
document.getElementById("onenamez").innerHTML = anOtherContestant.namee;
document.getElementById("onegpaz").innerHTML = anOtherContestant.collegeGpa;

};

console.log(anOtherContestant);
var contestantYou = {};

contestantYou.job = "Working for donald trump";
document.getElementById("status").innerHTML = contestantYou.job;
// create a property of this object called namee (name is a reserved word) based on the answer provided by the prompt (browser only)
contestantYou.namee =  prompt("Hello, and Welcome to the Apprentace. Pleast provide your name.");
document.getElementById("namez").innerHTML = contestantYou.namee;

if (contestantYou.namee === null) {
  console.log('please provide a valid name.');
}

// create a property of this object called party based on the answer provided by the prompt (browser only)
contestantYou.party = prompt("Thanks! Please provide your party.");
document.getElementById("partyz").innerHTML = contestantYou.party;

if (contestantYou.party === null) {
  console.log('Come on you can do this, please provide the party you most associate yourself with');
}

// create a property of this object called collegeGpa based on the answer provided by the prompt (browser only)
contestantYou.collegeGpa = prompt("Thanks! Please provide your colleg G.P.A.");
if (contestantYou.collegeGpa === null) {
  console.log('I know it is hard, but please provide yout true GPA.');
}
document.getElementById("gpaz").innerHTML = contestantYou.collegeGpa;

// create a property of this object called nationality based on the answer provided by the prompt (browser only)
contestantYou.nationality = prompt("Thanks! Please provide your nationality.");
if (contestantYou.nationality === null) {
  console.log('Come on, everyone comes from somewhere, please provide a valid nationality');
};
document.getElementById("nationalityz").innerHTML = contestantYou.nationality;

// print the contestant object (and its properties of course) in the console.
console.log(contestantYou);

document.getElementById("status").innerHTML = contestantYou.job;

function trump(){
  if (contestantYou.nationality === "Chinese" || contestantYou.collegeGpa > 80) {
    console.log("I love your nationality! You're promoted.");
    contestantYou.job = "PROMOTED!";
    anOtherContestant.job = "Demoted"
    document.getElementById("status").innerHTML = contestantYou.job;
  }
  else {
    contestantYou.job = "FIRED!"
    anOtherContestant.job = "Promoted"
    console.log("I hate you! You're fired!");
    document.getElementById("status").innerHTML = contestantYou.job;
  };

}
trump();

console.log(contestantYou);

// Reflection
//What was the most difficult part of this challenge?
// The hardes part of this challenge was getting user input to pop up on the screen. I learned about the document.getElementById("status").innerHTML = ...; method. This take whatever goes after the equal sign to display on the screen. This required one to build an html page as well.
//What did you learn about creating objects and functions that interact with one another?
// I learned that you need a variable to hold a function to access it in another function or if  you want to access a property you must precede it with the parent object name.
//Did you learn about any new built-in methods you could use in your refactored solution? If so, what were they and how do they work? I kind of jumped ahead of the material from this week and leared about the document.getElementById("element").innerHTML = object.property; This method  returns the element that has the ID attribute with the specified value. This method is one of the most common methods in the HTML DOM, and is used almost every time you want to manipulate, or get info from, an element on your document.
//How can you access and manipulate properties of objects?
//There are two ways to access properties of an obect.They are:1.)object.property 2.)object[property]
//
//
//
//
//<|endoftext|>


<commit_before>var mainState = {

	preload: function(){
		game.load.image('player', 'assets/player.png');
		game.load.image('wallV', 'assets/wallVertical.png');
		game.load.image('wallH', 'assets/wallHorizontal.png');
		game.load.image('coin', 'assets/coin.png');
		game.load.image('enemy', 'assets/enemy.png');
	},

	create: function(){
		game.stage.backgroundColor = "#3498db";
		game.physics.startSystem(Phaser.Physics.ARCADE);
		game.renderer.renderSession.roundPixels = true;

		//player
		this.player = game.add.sprite(game.width/2, game.height/2, 'player');
		this.player.anchor.setTo(0.5, 0.5);
		game.physics.arcade.enable(this.player);
		this.player.body.gravity.y = 500;

		//player control
		this.cursor = game.input.keyboard.createCursorKeys();

		//walls
		this.walls = game.add.group();
		this.walls.enableBody = true;
		game.add.sprite(0, 0, 'wallV', 0, this.walls);
		game.add.sprite(480, 0, 'wallV', 0, this.walls);

		game.add.sprite(0, 0, 'wallH', 0, this.walls);
		game.add.sprite(300,0, 'wallH', 0, this.walls);
		game.add.sprite(0,320, 'wallH', 0, this.walls);
		game.add.sprite(300,320, 'wallH', 0, this.walls);

		game.add.sprite(-100,160, 'wallH',0, this.walls);
		game.add.sprite(400,160, 'wallH',0, this.walls);

		var middleTop = game.add.sprite(100, 80, 'wallH', 0, this.walls);
		middleTop.scale.setTo(1.5, 1);
		var middleBottom = game.add.sprite(100, 240, 'wallH', 0, this.walls);
		middleBottom.scale.setTo(1.5, 1);

		this.walls.setAll('body.immovable', true);

		//coin
		this.coin = game.add.sprite(60, 140, 'coin');
		game.physics.arcade.enable(this.coin);
		this.coin.anchor.setTo(0.5, 0.5);

		this.scoreLabel = game.add.text(30, 30, 'score: 0',
			{font: '18px Arial', fill: '#ffffff'});
		this.score = 0;

		//create enemy group
		this.enemies = game.add.group();
		this.enemies.enableBody = true;
		//create 10 enemies
		this.enemies.createMultiple(10, 'enemy');
		//call add enemy every 2.2 second
		this.time.events.loop(2200, this.addEnemyFromTop, this);
		this.time.events.loop(2200, this.addEnemyFromBottom, this);
	},

	update: function(){
		//player
		game.physics.arcade.collide(this.player, this.walls);
		this.movePlayer();
		if (!this.player.inWorld){
			this.playerDie();
		}

		//coin
		game.physics.arcade.overlap(this.player, this.coin, this.takeCoin, null, this);

		//enemies
		game.physics.arcade.collide(this.enemies, this.walls);
		game.physics.arcade.overlap(this.player, this.enemies, this.playerDie, null, this);

		this.movePlayer();
		if (!this.player.inWorld) {
			this.playerDie();
		}
	},

	movePlayer: function(){
		if (this.cursor.left.isDown){
			this.player.body.velocity.x = -200;
		}
		else if (this.cursor.right.isDown){
			this.player.body.velocity.x = 200;
		}
		else {
			this.player.body.velocity.x = 0;
		}

		if (this.cursor.up.isDown && this.player.body.touching.down){
			this.player.body.velocity.y = -320;
		}
	},

	playerDie: function(){
		game.state.start("main");
	},

	updateCoinPosition: function(){
		var coinPosition = [
		{x: 140, y: 60}, {x: 360, y: 60},
		{x: 60, y: 140}, {x: 440, y: 140},
		{x: 130, y: 300}, {x: 370, y: 300},
		];

		for (var i = 0; i < coinPosition.length; i++){
			if(coinPosition[i].x ==this.coin.x) {
				coinPosition.splice(i, 1);
			}
		}
		var newPosition = game.rnd.pick(coinPosition);
		this.coin.reset(newPosition.x, newPosition.y);
	},

	takeCoin: function(player, coin){
		this.coin.kill();
		this.score += 5;
		this.scoreLabel.text = 'score: ' + this. score;
		this.updateCoinPosition();
	},

//add enemy function
	addEnemyFromTop: function() {
		//get 1st dead enemy of group
		var enemy = this.enemies.getFirstDead();
		//do nothing if no enemy
		if (!enemy) {
			return;
		}

		//initialize an enemy
		//set anchor to  center bottom
		enemy.anchor.setTo(0.5, 1);
		enemy.reset(game.width/2, 0);
		//add gravity
		enemy.body.gravity.y = 500;
		enemy.body.velocity.x = 100 * game.rnd.pick([-1, 1]);

		enemy.body.bounce.x = 1;
		enemy.checkWorldBounds = true;
		enemy.outOfBoundsKill = true;
	},

	addEnemyFromBottom: function() {
		var enemy = this.enemies.getFirstDead();

		if (!enemy) {
			return;
		}

		//initialize an enemy
		enemy.anchor.setTo(0.5, 1);
		//add enemy from
		enemy.reset(game.width/2, game.height);
		//add gravity
		enemy.body.gravity.y = -500;
		enemy.body.velocity.x = 100 * game.rnd.pick([-1, 1]);
		enemy.body.bounce.x = 1;
		enemy.checkWorldBounds = true;
		enemy.outOfBoundsKill = true;
	},
};

var game = new Phaser.Game(500,340, Phaser.AUTO, 'gameDiv');
game.state.add('main', mainState);
game.state.start('main');<commit_msg>minor change<commit_after>var mainState = {

	preload: function(){
		game.load.image('player', 'assets/player.png');
		game.load.image('wallV', 'assets/wallVertical.png');
		game.load.image('wallH', 'assets/wallHorizontal.png');
		game.load.image('coin', 'assets/coin.png');
		game.load.image('enemy', 'assets/enemy.png');
	},

	create: function(){
		game.stage.backgroundColor = "#3498db";
		game.physics.startSystem(Phaser.Physics.ARCADE);
		game.renderer.renderSession.roundPixels = true;

		//player
		this.player = game.add.sprite(game.width/2, game.height/2, 'player');
		this.player.anchor.setTo(0.5, 0.5);
		game.physics.arcade.enable(this.player);
		this.player.body.gravity.y = 500;

		//player control
		this.cursor = game.input.keyboard.createCursorKeys();

		//walls
		this.walls = game.add.group();
		this.walls.enableBody = true;
		game.add.sprite(0, 0, 'wallV', 0, this.walls);
		game.add.sprite(480, 0, 'wallV', 0, this.walls);

		game.add.sprite(0, 0, 'wallH', 0, this.walls);
		game.add.sprite(300,0, 'wallH', 0, this.walls);
		game.add.sprite(0,320, 'wallH', 0, this.walls);
		game.add.sprite(300,320, 'wallH', 0, this.walls);

		game.add.sprite(-100,160, 'wallH',0, this.walls);
		game.add.sprite(400,160, 'wallH',0, this.walls);

		var middleTop = game.add.sprite(100, 80, 'wallH', 0, this.walls);
		middleTop.scale.setTo(1.5, 1);
		var middleBottom = game.add.sprite(100, 240, 'wallH', 0, this.walls);
		middleBottom.scale.setTo(1.5, 1);

		this.walls.setAll('body.immovable', true);

		//coin
		this.coin = game.add.sprite(60, 140, 'coin');
		game.physics.arcade.enable(this.coin);
		this.coin.anchor.setTo(0.5, 0.5);

		this.scoreLabel = game.add.text(30, 30, 'score: 0',
			{font: '18px Arial', fill: '#ffffff'});
		this.score = 0;

		//create enemy group
		this.enemies = game.add.group();
		this.enemies.enableBody = true;
		//create 10 enemies
		this.enemies.createMultiple(10, 'enemy');
		//call add enemy every 2.2 second
		this.time.events.loop(2200, this.addEnemyFromTop, this);
		this.time.events.loop(2200, this.addEnemyFromBottom, this);
	},

	update: function(){
		//player
		game.physics.arcade.collide(this.player, this.walls);
		this.movePlayer();
		if (!this.player.inWorld){
			this.playerDie();
		}

		//coin
		game.physics.arcade.overlap(this.player, this.coin, this.takeCoin, null, this);

		//enemies
		game.physics.arcade.collide(this.enemies, this.walls);
		game.physics.arcade.overlap(this.player, this.enemies, this.playerDie, null, this);

		this.movePlayer();
		if (!this.player.inWorld) {
			this.playerDie();
		}
	},

	movePlayer: function(){
		if (this.cursor.left.isDown){
			this.player.body.velocity.x = -200;
		}
		else if (this.cursor.right.isDown){
			this.player.body.velocity.x = 200;
		}
		else {
			this.player.body.velocity.x = 0;
		}

		if (this.cursor.up.isDown && this.player.body.touching.down){
			this.player.body.velocity.y = -320;
		}
	},

	playerDie: function(){
		game.state.start("main");
	},

	updateCoinPosition: function(){
		var coinPosition = [
		{x: 140, y: 60}, {x: 360, y: 60},
		{x: 60, y: 140}, {x: 440, y: 140},
		{x: 130, y: 300}, {x: 370, y: 300},
		];

		for (var i = 0; i < coinPosition.length; i++){
			if(coinPosition[i].x ==this.coin.x) {
				coinPosition.splice(i, 1);
			}
		}
		var newPosition = game.rnd.pick(coinPosition);
		this.coin.reset(newPosition.x, newPosition.y);
	},

	takeCoin: function(player, coin){
		this.coin.kill();
		this.score += 5;
		this.scoreLabel.text = 'score: ' + this. score;
		this.updateCoinPosition();
	},

//add enemy function
	addEnemyFromTop: function() {
		//get 1st dead enemy of group
		var enemy = this.enemies.getFirstDead();
		//do nothing if no enemy
		if (!enemy) {
			return;
		}

		//initialize an enemy
		//set anchor to  center bottom
		enemy.anchor.setTo(0.5, 1);
		enemy.reset(game.width/2, 0);
		//add gravity
		enemy.body.gravity.y = 500;
		enemy.body.velocity.x = 100 * game.rnd.pick([-1, 1]);

		enemy.body.bounce.x = 1;
		enemy.checkWorldBounds = true;
		enemy.outOfBoundsKill = true;
	},

	addEnemyFromBottom: function() {
		var enemy = this.enemies.getFirstDead();

		if (!enemy) {
			return;
		}

		//initialize an enemy
		enemy.anchor.setTo(0.5, 1);
		//add enemy from bottom
		enemy.reset(game.width/2,0);
		//add gravity
		enemy.body.gravity.y = -500;
		enemy.body.velocity.x = 100 * game.rnd.pick([-1, 1]);
		enemy.body.bounce.x = 1;
		enemy.checkWorldBounds = true;
		enemy.outOfBoundsKill = true;
	},
};

var game = new Phaser.Game(500,340, Phaser.AUTO, 'gameDiv');
game.state.add('main', mainState);
game.state.start('main');<|endoftext|>