Skip to content

Instantly share code, notes, and snippets.

class Connect4 {
constructor() {
// 7 columns and 6 rows
this.column = [0, 0, 0, 0, 0, 0];
this.currentPlayer = 1; // 2
}
play(col) {
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>GOES IN THE TOP TAB</title>
</head>
<body>
<!-- <div>fdsfds</div>
@natafaye
natafaye / boggle.js
Created July 6, 2022 03:46
7/5/22 - JS Week 6
class Die {
constructor(letters) {
this.topLetter = letters[0];
this.allLetters = letters;
}
roll() {
const randomIndex = Math.floor(Math.random() * this.allLetters.length)
this.topLetter = this.allLetters[randomIndex];
}
@natafaye
natafaye / boggle.js
Last active July 6, 2022 03:43
JS Week 6 - 7/5/22 class
class Die {
// letters = array of strings of letters on this die
constructor(letters) {
this.allLetters = letters;
this.currentLetter = letters[0]
}
reroll() {
const randomIndex = Math.floor(Math.random() * this.allLetters.length)
this.currentLetter = this.allLetters[randomIndex];
class User {
constructor(username) { // firstName = "Natalie"; lastName = "Childs"
this.username = username;
this.isAdmin = false;
}
greet() {
alert("Hello " + this.username + "!")
}
class AcceptedAnswerPrompt {
constructor(acceptableAnswers) { // acceptableAnswers = ["cat", "dog", "unicorn"]
this.acceptableAnswers = acceptableAnswers;
}
promptForAcceptable(question) {
let answer = prompt(question); // calling normal Javascript prompt
// let foundAnswer = undefined;
/***** Converting Between Arrow and Normal Functions *****/
// Normal Function
function isJose(user) {
return user.username === "jose"
}
// Arrow Function
const isJose = (user) => {
return user.username === "jose"
/***** Converting a Normal Function to an Arrow Function ******/
function isJose(user) {
return user.username === "jose"
}
// converted to arrow function syntax
const isJose = (user) => {
return user.username === "jose"
}
/******** Arrays ********/
let names = [
"Abigail",
"Marco",
"Simone",
"Derek"
]
console.log(names);
/******** Arrays ********/
let names = [
"Abigail",
"Marco",
"Simone",
"Derek"
]
let allTheNames = ""