Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended"
],
"overrides": [
],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"react"
],
"rules": {
}
}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/**/.DS_Store
node_modules
node_modules
116 changes: 116 additions & 0 deletions bowling.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
class Bowling {
constructor() {
this.score = 0
this.frameNum = []
this.spare = 0
this.strike = 0
};

getScore(){
if(this.strike+this.spare === 1){
return `${this.score} + 1 roll`
}
else if(this.strike > 0 || this.spare >0){
return `${this.score} + ${this.strike+this.spare} rolls`
}

return this.score
}

addScores(num1, num2){

if (this.frameNum.length >9){
return this.extraRoll(num1,num2)
}
if (this.strike === 3){
this.frameNum[this.frameNum.length-2][2] = num1;
this.strike--;
this.score += num1

}
if (this.spare === 1) {
this.frameNum[this.frameNum.length-1][2] = num1;
this.spare--;
this.score += num1
}

if(this.strike === 2 && num1 === 10 ){
this.frameNum[this.frameNum.length-1][1] = num1;
this.strike--;
this.score += num1

}
if (this.strike === 2 ) {
this.frameNum[this.frameNum.length-1][1] = num1;
this.frameNum[this.frameNum.length-1][2] = num2;
this.strike--;
this.strike--;
this.score += num1
this.score += num2
}
if(num1 === 10) {
this.score += 10
this.frameNum.push([num1])
this.strike +=2
this.frameNum[this.frameNum.length-1].push('roll')
this.frameNum[this.frameNum.length-1].push('roll')
}
else if (num1+num2 === 10) {
this.score += num1+num2
this.frameNum.push([num1, num2])
this.spare++
this.frameNum[this.frameNum.length-1].push('roll')
}
else {
this.score += num1+num2
this.frameNum.push([num1, num2])
}
if(this.frameNum.length === 10 && this.spare+this.strike >0){

return 'extra roll'

}
if (this.frameNum.length >=10 ){
return `Well done your final score is ${this.score}`
}
}

extraRoll(num1,num2){
if (this.spare === 1) {
this.frameNum[this.frameNum.length-1][2] = num1;
this.spare--;
this.score += num1
}
if (this.strike === 3){
this.frameNum[this.frameNum.length-2][2] = num1;
this.strike--;
this.score += num1

}
if (this.strike === 2 ) {
this.frameNum[this.frameNum.length-1][1] = num1;
this.frameNum[this.frameNum.length-1][2] = num2;
this.strike--;
this.strike--;
this.score += num1
this.score += num2
}
if (this.frameNum.length >=10 ){
return `Well done your final score is ${this.score}`
}
}
getFrame(num){

return this.frameNum[num-1]

}
reset() {
this.score = 0
this.frameNum = []
this.spare = 0
this.strike = 0
}
}


module.exports = Bowling
Loading