-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmini-game.js
34 lines (28 loc) · 824 Bytes
/
mini-game.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function start(){
let playerScore = randomScore()
setScore("player-number", playerScore)
let computerScore = randomScore()
setScore("computer-number", computerScore)
if(playerScore > computerScore){
// player menang
setWinner("Pemenangnya adalah Player")
}else if(playerScore < computerScore){
// computer menang
setWinner("Pemenangnya adalah Computer")
}else{
// seri
setWinner("Permainan seri")
}
}
function setWinner(text){
let winner = document.getElementById("winner")
winner.textContent = text
}
function setScore(elementId, score){
let scoreElement = document.getElementById(elementId)
scoreElement.textContent = score
}
function randomScore(){
let score = Math.floor(Math.random() * 100 + 1)
return score
}