Challenge: Adapter Pattern
In this challenge, you have to implement the adapter pattern to solve the given problem.
We'll cover the following...
We'll cover the following...
Problem statement
In this challenge, you are given a TruthAndDare
program like this:
Press + to interact
Node.js
// old interfaceclass TruthAndDare {constructor(){this.turn = Math.floor(Math.random() * 2) + 1;}Getturn(){if(this.turn == 1){this.turn = 2}else{this.turn = 1}return this.turn}playGame(playerOnename,playerTwoname){if(this.Getturn() == 1){return`${playerOnename}'s turn`}else{return `${playerTwoname}'s turn`}}}const obj = new TruthAndDare()console.log(obj.playGame("Ross","Chandler"))
There is a variable turn
that decides which player’s turn it is to give a dare or ask a question. The Getturn()
function is used to set and return the turn
. It is set to either 1 or 2. The playGame
function is simple: it takes two players and depending on the ...