From 423cb6b0982eb4c276d636b57d9fce095a522f2c Mon Sep 17 00:00:00 2001 From: Maxheart Date: Tue, 20 Oct 2020 00:23:17 +0800 Subject: [PATCH] add review --- index.html | 6 ++++++ javascript.js | 25 ++++++++++++++++++++++++- style.css | 3 +++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 887deb4..ceb282d 100644 --- a/index.html +++ b/index.html @@ -7,8 +7,10 @@ +
+

Rock Paper Scissor

Let's play! What you got?

@@ -17,19 +19,23 @@
+

Play and see your luck :)

Wins

+

-

+

Loses

-

+
Made by Edward Alvin, visit github.com/ThePrevailingOne/ for more
diff --git a/javascript.js b/javascript.js index 5d8ef1e..c3a949b 100644 --- a/javascript.js +++ b/javascript.js @@ -1,37 +1,58 @@ + +// Global variables >< let wins = 0; let loses = 0; + +// hapus semua console lognya setelah selesai local testing console.log("olaa"); const res = document.querySelector("#tulisan"); + +// winp sama losep agak confusing (winPointNode atau losePointNode mungkin, js pake camelCase haha) let winp = document.querySelector("#winscore"); let losep = document.querySelector("#losescore"); + +// console log console.log(res.textContent); console.log("hello"); +// Naming, I think playem is not a good name, simply playRoundWith(playerMove) itu mungkin lebih enak dibaca function playem(move) { let choice = Math.floor(Math.random()*3); let compMoves = ['rock', 'paper', 'scissor']; let compMove = compMoves[choice]; + // console log console.log(choice); determiner(move, compMove); } + +// Naming, I think handleWin is a much better name +// there shouldnt be any space after function nam,e function win (player, comp) { wins += 1; winp.textContent = wins; res.textContent = "You beat " + comp + " with " + player + ", nice!" } +// sama kayak di atas function lose (player, comp) { loses += 1; losep.textContent = loses; res.textContent = "Boo, your " + player + " lose to " + comp + "!"; } +// comp variable is not used function tie(player, comp) { res.textContent = "Looks like it's a tie between " + player + "!"; } +// Naming, probably handleResult atau semacamnya is a better name function determiner (player, comp) { + // btw daripada pake string gini enak pake enum: https://www.sohamkamani.com/blog/2017/08/21/enums-in-javascript/ + // kalo string gini typo 1 gg hahaha + + // Javascript equalizernya pake ===, bukan ==. Banyak hal menarik bisa terjadi kalo pake == + // Basically === itu determine dia same type sama same value if (player == 'rock') { if (comp == 'scissor') { win(player, comp); @@ -39,6 +60,7 @@ function determiner (player, comp) { lose(player, comp); } else { tie(player, comp); + // unnecessary semicolon, abis if braces ga perlu semicolon }; } else if (player == 'paper') { if (comp == 'scissor') { @@ -57,4 +79,5 @@ function determiner (player, comp) { lose(player, comp); }; } -} \ No newline at end of file +} +// Biasain kasih endline after the last line diff --git a/style.css b/style.css index 27666d6..7d96aac 100644 --- a/style.css +++ b/style.css @@ -1,6 +1,8 @@ @import url('https://fonts.googleapis.com/css2?family=Baloo+Tamma+2:wght@500&display=swap'); +/*global? biasanya gini ditaruhnya di body*/ * { + /*buat 0 biasa ga pake 0px*/ margin: 0px; font-family: 'Baloo Tamma 2', cursive; color: white; @@ -45,6 +47,7 @@ button:hover { } button:active { + /* shld use 0 instead of 0px */ box-shadow: 0px 10px 20px rgba(0, 0, 0, 0.2); }