JS Quiz # 3

by Bilal Zafar

JavaScript

const Pair = function (first, second) {
	this.first = first;
  this.second = second;
};

Pair.prototype.setFirst = function(newFirst) {
	this.first = newFirst;
  return this;
};

Pair.prototype.setSecond = function(newSecond) {
	this.second = newSecond;
  return this;
};

const arr = [];
arr[0] = new Pair("first", "second");
arr[1] = arr[0].setFirst("second");
arr[2] = arr[1].setSecond("first");

if (arr[0] === arr[1] || arr[0] === arr[2] || arr[1] === arr[2]) {
	arr[0].setSecond("second").setFirst("first");
}
else {
	arr[1].setFirst("third").setSecond("third");
}

console.log(arr[0].first);
console.log(arr[2].second);

/* Answer is:
second
first
*/