Build JavaScript ROCK PAPER SCISSORS in 18 minutes! 👊

  Рет қаралды 23,840

Bro Code

Bro Code

6 ай бұрын

#JavaScript #tutorial #course
This is a beginner's project to help learn the fundamentals of working with the DOM and classList

Пікірлер: 53
@BroCodez
@BroCodez 5 ай бұрын
// ROCK PAPER SCISSORS const choices = ["rock", "paper", "scissors"]; const playerDisplay = document.getElementById("playerDisplay"); const computerDisplay = document.getElementById("computerDisplay"); const resultDisplay = document.getElementById("resultDisplay"); const playerScoreDisplay = document.getElementById("playerScoreDisplay"); const computerScoreDisplay = document.getElementById("computerScoreDisplay"); let playerScore = 0; let computerScore = 0; function playGame(playerChoice){ const computerChoice = choices[Math.floor(Math.random() * 3)]; let result = ""; if(playerChoice === computerChoice){ result = "IT'S A TIE!"; } else{ switch(playerChoice){ case "rock": result = (computerChoice === "scissors") ? "YOU WIN!" : "YOU LOSE!"; break; case "paper": result = (computerChoice === "rock") ? "YOU WIN!" : "YOU LOSE!"; break; case "scissors": result = (computerChoice === "paper") ? "YOU WIN!" : "YOU LOSE!"; break; } } playerDisplay.textContent = `PLAYER: ${playerChoice}`; computerDisplay.textContent = `Computer: ${computerChoice}`; resultDisplay.textContent = result; resultDisplay.classList.remove("greenText", "redText"); switch(result){ case "YOU WIN!": resultDisplay.classList.add("greenText"); playerScore++; playerScoreDisplay.textContent = playerScore; break; case "YOU LOSE!": resultDisplay.classList.add("redText"); computerScore++; computerScoreDisplay.textContent = computerScore; break; } } Document Rock - Paper - Scissors 👊 ✋ ✌ PLAYER: COMPUTER: Player Score: 0 Computer Score: 0 body{ font-family: Arial, sans-serif; font-weight: bold; margin: 0; display: flex; flex-direction: column; align-items: center; } h1{ font-size: 3.5rem; color: hsl(0, 0%, 20%); } .choices{ margin-bottom: 30px; } .choices button{ font-size: 7.5rem; min-width: 160px; margin: 0 10px; border-radius: 250px; background-color: hsl(200, 100%, 50%); cursor: pointer; transition: background-color 0.5s ease; } .choices button:hover{ background-color: hsl(200, 100%, 70%); } #playerDisplay, #computerDisplay{ font-size: 2.5rem; } #resultDisplay{ font-size: 5rem; margin: 30px 0; } .scoreDisplay{ font-size: 2rem; } .greenText, #playerScoreDisplay{ color: hsl(130, 84%, 54%); } .redText, #computerScoreDisplay{ color: hsl(0, 84%, 60%); }
@cpu_governor
@cpu_governor 5 ай бұрын
@BroCodez why are you creating a new javascript playlist, will the old one be deleted ?
@mahithmahi9446
@mahithmahi9446 3 ай бұрын
Can you send full code ......
@shieldanime6968
@shieldanime6968 3 ай бұрын
You are a lifesaver brocodez 💪💪💪🎉🎊🎉🎊🎉🎆🎇🎆🎇🎆🎇🙏🙏🙏
@IanAdaque
@IanAdaque 23 күн бұрын
Bro how about if your code said choice is not defined
@OrionsFactFactory
@OrionsFactFactory 5 ай бұрын
I just wanna say you are every Computer Science students hero man❤
@hasnainmalik8982
@hasnainmalik8982 5 ай бұрын
Hey bro I am your permanent subscriber from India if nobody is watching your video or you are getting only one view I am sure that I will be that one viewer watching your videoa
@sadboy-xx6gh
@sadboy-xx6gh 5 ай бұрын
I'm from India too and I've been watching his videos for more than a year. I've seen some video tutorials more than 10 times. For some of them going for as long as 12 hours.
@mosshead_vinsmoke
@mosshead_vinsmoke Ай бұрын
@@sadboy-xx6gh same here, Indian channel are good but they are boring but my Man here knows how to teach in a fun whimsical way + he is the get to guy when you wanna review some concepts or topics
@jiyoungkim9258
@jiyoungkim9258 5 ай бұрын
you're my life saver!
@silviocorrea25
@silviocorrea25 5 ай бұрын
Great content
@Adithyarmenon198
@Adithyarmenon198 5 ай бұрын
Nice Program I am also doing almost similar ones😃
@gyisu
@gyisu 5 ай бұрын
Are you going to create a flutter course? It would be really cool. Good tutorial bro :)
@festussabu
@festussabu 5 ай бұрын
hey can you do a video about how intersection observer works in react..
@gatenetsetgo....7012
@gatenetsetgo....7012 5 ай бұрын
Please,make full tutorial from basic to advance
@doronfeldman5152
@doronfeldman5152 5 ай бұрын
Hey bro, are you going to do a node.js course in the future?
@charlesselrachski34
@charlesselrachski34 5 ай бұрын
i like, can you do next one with gdscript4 and android app, and another with flutter and android app with leaderboards
@opiirix3302
@opiirix3302 5 ай бұрын
How did you learn front-end development? I'm just having trouble finding a beneficial course for me; however, some videos like your HTML/CSS/JavaScript or the CS50web dev course have been really helpful for me
@jobnacorconcepcionabad6037
@jobnacorconcepcionabad6037 5 ай бұрын
I recommendo you the Odin Project
@Birandoo
@Birandoo 3 ай бұрын
Check out "The Odin Project". I highly recommend it. I'm taking it now. Online, free and good for what you will need for getting a job later.
@ArtistikNoName
@ArtistikNoName 5 ай бұрын
can u make a full course of lua, please?
@gamingwithyoungtrouble
@gamingwithyoungtrouble 5 ай бұрын
How didu make that website
@l-fitness3590
@l-fitness3590 4 ай бұрын
For anyone having problems put the script link before the last body tag not in the head section
@hiya1399
@hiya1399 28 күн бұрын
THANK YOU!!! I've been working on this for hours and couldn't figure out why it wasn't working.
@l-fitness3590
@l-fitness3590 28 күн бұрын
@@hiya1399 been a while since I put this comment but you can put it in the head but add defer
@lucasquinncreations
@lucasquinncreations 9 күн бұрын
Thank you! Why does having the script in the html header break functions like this?
@l-fitness3590
@l-fitness3590 9 күн бұрын
@@lucasquinncreations I might be incorrect so take what I say with a pinch of salt but by adding defer your letting the html load first
@lucasquinncreations
@lucasquinncreations 9 күн бұрын
@@l-fitness3590 I see it. Perhaps a case of needing the text fields loaded first before changing them.
@cryptoptinvestor384
@cryptoptinvestor384 4 ай бұрын
For me to add some emojis "Windows Key + ." Win+.
@did_someoneknow
@did_someoneknow 20 күн бұрын
Why my code is not working?
@GnomeBobMC
@GnomeBobMC 5 ай бұрын
First 🤓
@BroCodez
@BroCodez 5 ай бұрын
You win! 🎊
@GnomeBobMC
@GnomeBobMC 5 ай бұрын
@@BroCodez No way this legend actually responded 🥳🎉
@AvidAfrican
@AvidAfrican 5 ай бұрын
Bro code came in 2024 loaded... i'm following you...
@oybekabdumalikov2763
@oybekabdumalikov2763 5 ай бұрын
Coding bootcamps hate you and also their businesses are in minus 😂
@HKkinner
@HKkinner 5 ай бұрын
pls pin me i am 7th
@user-gx6zp4tv7f
@user-gx6zp4tv7f 5 ай бұрын
it aint working
@l-fitness3590
@l-fitness3590 4 ай бұрын
Did you find the solution
@user-gx6zp4tv7f
@user-gx6zp4tv7f 4 ай бұрын
@@l-fitness3590 no
@-ASTROMAGIC
@-ASTROMAGIC 3 ай бұрын
you need to to return the result at the end of the playGame function and it should work. not really sure why his doesn't produce an error
@-ASTROMAGIC
@-ASTROMAGIC 3 ай бұрын
his switch cases are also incomplete and will produce bugs, but it's nothing that can't be fixed by going on stackoverflow.
@0nullBit
@0nullBit 3 ай бұрын
@@-ASTROMAGIC what why does the play game need to return anything. Also the switch should work perfectly fine….
Build a JavaScript IMAGE SLIDER in 15 minutes! 🖼️
15:49
Bro Code
Рет қаралды 31 М.
Build this JS STOPWATCH in 18 minutes! ⏱
18:06
Bro Code
Рет қаралды 19 М.
🍕Пиццерия FNAF в реальной жизни #shorts
00:41
World’s Deadliest Obstacle Course!
28:25
MrBeast
Рет қаралды 92 МЛН
La revancha 😱
00:55
Juan De Dios Pantoja 2
Рет қаралды 67 МЛН
Khóa ly biệt
01:00
Đào Nguyễn Ánh - Hữu Hưng
Рет қаралды 19 МЛН
Create Rock Paper Scissors in Java in 10 Minutes
10:24
Coding with John
Рет қаралды 106 М.
What are JavaScript PROMISES? 🤞
12:37
Bro Code
Рет қаралды 40 М.
Calculator App in HTML CSS and JavaScript
33:43
Code Braces
Рет қаралды 4,3 М.
Урок 5. JavaScript. Promise. Что это, как работает (+ пример)
23:18
Build this JS calculator in 15 minutes! 🖩
15:20
Bro Code
Рет қаралды 382 М.
Learn Javascript  Rock, Paper, Scissors
26:28
CodeWithRana
Рет қаралды 9 М.
If __name__ == "__main__" for Python Developers
8:47
Python Simplified
Рет қаралды 380 М.
What is JavaScript CALLBACK HELL? 🔥
5:49
Bro Code
Рет қаралды 16 М.
Build a JavaScript WEATHER APP in 30+ minutes! ☀️
38:40
Bro Code
Рет қаралды 33 М.
Code Space Invaders in JavaScript!
45:32
Code with Ania Kubów
Рет қаралды 19 М.
🍕Пиццерия FNAF в реальной жизни #shorts
00:41