Created
July 28, 2021 01:23
-
-
Save natafaye/9483c44accfb127c3ca8f2636ee4be01 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Die { | |
constructor(possibleLetters) { | |
this.possibleLetters = possibleLetters; // this could be: ["A", "E", "P", "L"] | |
this.letter = possibleLetters[0]; // just set it to the first one as a placeholder and then we'll shuffle it | |
this.shuffle(); | |
} | |
shuffle() { | |
const randomIndex = Math.floor(Math.random() * this.possibleLetters.length); // this might generate: 0, 1, 2, 3 | |
this.letter = this.possibleLetters[randomIndex]; | |
} | |
} | |
class Board { | |
constructor() { | |
this.dice = []; | |
const firstDie = new Die(["A", "E", "P", "L"]); | |
this.dice.push(firstDie) | |
// We could add a bunch more die here | |
this.shuffle(); | |
} | |
shuffle() { | |
this.dice.forEach(die => { | |
die.shuffle(); | |
}) | |
// This just a quick and dirty array shuffling code that we found on StackOverflow | |
this.dice.sort(() => Math.random() - 0.5); | |
} | |
getAllWords() { | |
// Get all the words in this current set up of the boggle board | |
} | |
toString() { | |
// create a nice string display of the board so we can alert or console.log that out | |
} | |
} | |
const board = new Board(); // We'll create the board outside the function so it only gets created once | |
function start() { | |
// Each time we run this function: shuffle the board, show the board, find all the words, show all the words | |
board.shuffle(); | |
alert(board.toString()); | |
const words = board.getAllWords() // words will be an array of words (strings) | |
alert(words); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const expect = chai.expect; | |
describe('QuestionPrompt', function() { | |
describe('constructor', function() { | |
it('should set up the properties correctly', function() { | |
let question = "Question?"; | |
let acceptedAnswers = ["accepted", "answers"]; | |
let qPrompt = new QuestionPrompt(question, acceptedAnswers) | |
expect(qPrompt.question).to.be.a('string'); | |
expect(qPrompt.question).to.equal(question); | |
expect(qPrompt.acceptedAnswers).to.be.a('array'); | |
expect(qPrompt.acceptedAnswers).to.equal(acceptedAnswers); | |
}) | |
}) | |
describe('getAcceptedAnswers', function() { | |
it('should return the matching accepted answer (case insensitive)', function() { | |
const acceptedAnswers = ["AaAA", "bBBB", "Cccc", "dddd"] | |
let qPrompt = new QuestionPrompt("Q", acceptedAnswers); | |
expect(qPrompt.getAcceptedAnswer("aaaa")).to.equal(acceptedAnswers[0]); // acceptedAnswers[0] is "AaAA" | |
expect(qPrompt.getAcceptedAnswer("aAaA")).to.equal(acceptedAnswers[0]); | |
expect(qPrompt.getAcceptedAnswer("AAAA")).to.equal(acceptedAnswers[0]); | |
expect(qPrompt.getAcceptedAnswer("BBbb")).to.equal(acceptedAnswers[1]); // acceptedAnswers[1] is "bBBB" | |
expect(qPrompt.getAcceptedAnswer("cCCC")).to.equal(acceptedAnswers[2]); // acceptedAnswers[2] is "Cccc" | |
expect(qPrompt.getAcceptedAnswer("DDDd")).to.equal(acceptedAnswers[3]); // acceptedAnswers[3] is "dddd" | |
}) | |
it('should return undefined if does not match any of the accepted answers', function() { | |
const acceptedAnswers = ["AaAA", "bBBB", "Cccc", "dddd"] | |
let qPrompt = new QuestionPrompt("Q", acceptedAnswers); | |
expect(qPrompt.getAcceptedAnswer("aaaB")).to.equal(undefined); | |
expect(qPrompt.getAcceptedAnswer("aaaaa")).to.equal(undefined); | |
expect(qPrompt.getAcceptedAnswer("AaAAbBBB")).to.equal(undefined); | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment