Best JavaScript code snippet using pact-foundation-pact
game_revisiting.js
Source:game_revisiting.js
1const firstContainer = document.querySelector('#gameButtons')2const secondContainer = document.querySelector('#scores')3const invisibleButton = document.querySelector('button')4let startRound = document.createElement('div');5const updatedResult = document.createElement('div');6const updatedScores = document.createElement('div');7var newcomputerSelection;8var playerScore = 0;9var computerScore = 0;10var drawScore = 0;11const rockbtn = document.querySelector('#rockbtn');12const paperbtn = document.querySelector('#paperbtn');13const scizzorsbtn = document.querySelector('#scizzorsbtn');14// DOM Manipulation15startRound.textContent = "Choose one to play a round of Rock, Paper, Scizzors. First to 5 wins!";16startRound.style.cssText = "border: 2px solid black; font-size: 20px; display:inline-block; padding: 15px;"17updatedScores.textContent = "Your Score:" + " " + playerScore + " | " + "Computer'\s Score:" + " " + computerScore + " | " + "Draws:" + " " + drawScore;18updatedResult.textContent = "Play a round to see the result!"19secondContainer.appendChild(startRound);20secondContainer.appendChild(updatedScores);21secondContainer.appendChild(updatedResult);22// Click event listeners to play the game23rockbtn.addEventListener('click', function (e) {24 let roundResult = playRound('Rock');25 if (roundResult.charAt(4) === 'w'){ // This is used to recognize the outcome from the playRound(); function.26 playerScore++;27 console.log("The score is" + " " + playerScore + " " + "to" + " " + computerScore);28 updatedResult.textContent = "You won! Your opponent chose" + " " + "Scizzors" + " " + "which loses to" + " " + "Rock" + ".";29 updatedScores.textContent = "Your Score:" + " " + playerScore + " | " + "Computer'\s Score:" + " " + computerScore + " | " + "Draws:" + " " + drawScore;30 }31 if (roundResult.charAt(4) === 'l'){32 computerScore++;33 console.log("The score is" + " " + playerScore + " " + "to" + " " + computerScore);34 updatedResult.textContent = "You lost! Your opponent chose" + " " + "Paper" + " " + "which beats" + " " + "Rock" + ".";35 updatedScores.textContent = "Your Score:" + " " + playerScore + " | " + "Computer'\s Score:" + " " + computerScore + " | " + "Draws:" + " " + drawScore;36 }37 if (roundResult.charAt(0) === 'I'){38 drawScore++;39 console.log("No points added to either player. The current score is" + " " + playerScore + " " + "to" + " " + computerScore + ".");40 updatedResult.textContent = "It's a draw! No Points have been added. Your opponent also chose" + " " + "Rock" + ".";41 updatedScores.textContent = "Your Score:" + " " + playerScore + " | " + "Computer's Score:" + " " + computerScore + " | " + "Draws:" + " " + drawScore;42 }43 // Ends the game if either the player or computer reaches a score of 544 if (playerScore === 5) {45 startRound.textContent = "The game has ended. You won! Refresh the page to play again."46 // Makes buttons disappear so you can't play anymore47 rockbtn.style.display = "none";48 paperbtn.style.display = "none";49 scizzorsbtn.style.display = "none";50 } else if (computerScore === 5){51 startRound.textContent = "The game has ended. You lost! Refresh the page to play again."52 // Makes buttons disappear so you can't play anymore53 rockbtn.style.display = "none";54 paperbtn.style.display = "none";55 scizzorsbtn.style.display = "none";56 } 57});58paperbtn.addEventListener('click', function (e) {59 let roundResult = playRound('Paper');60 if (roundResult.charAt(4) === 'w'){ // This is used to recognize the outcome from the playRound(); function.61 playerScore++;62 console.log("The score is" + " " + playerScore + " " + "to" + " " + computerScore);63 updatedResult.textContent = "You won! Your opponent chose" + " " + "Rock" + " " + "which loses to" + " " + "Paper" + ".";64 updatedScores.textContent = "Your Score:" + " " + playerScore + " | " + "Computer'\s Score:" + " " + computerScore + " | " + "Draws:" + " " + drawScore; 65 }66 if (roundResult.charAt(4) === 'l'){67 computerScore++;68 console.log("The score is" + " " + playerScore + " " + "to" + " " + computerScore);69 updatedResult.textContent = "You lost! Your opponent chose" + " " + "Scizzors" + " " + "which beats" + " " + "Paper" + ".";70 updatedScores.textContent = "Your Score:" + " " + playerScore + " | " + "Computer'\s Score:" + " " + computerScore + " | " + "Draws:" + " " + drawScore;71 }72 if (roundResult.charAt(0) === 'I'){73 drawScore++;74 console.log("No points added to either player. The current score is" + " " + playerScore + " " + "to" + " " + computerScore + ".");75 updatedResult.textContent = "It's a draw! No Points have been added. Your opponent also chose" + " " + "Paper" + ".";76 updatedScores.textContent = "Your Score:" + " " + playerScore + " | " + "Computer's Score:" + " " + computerScore + " | " + "Draws:" + " " + drawScore;77 }78 // Ends the game if either the player or computer reaches a score of 579 if (playerScore === 5) {80 startRound.textContent = "The game has ended. You won! Refresh the page to play again."81 // Makes buttons disappear so you can't play anymore82 rockbtn.style.display = "none";83 paperbtn.style.display = "none";84 scizzorsbtn.style.display = "none";85 } else if (computerScore === 5){86 startRound.textContent = "The game has ended. You lost! Refresh the page to play again."87 88 // Makes buttons disappear so you can't play anymore89 rockbtn.style.display = "none";90 paperbtn.style.display = "none";91 scizzorsbtn.style.display = "none";92 } 93});94scizzorsbtn.addEventListener('click', function (e) {95 let roundResult = playRound('Scizzors');96 if (roundResult.charAt(4) === 'w'){ // This is used to recognize the outcome from the playRound(); function.97 playerScore++;98 console.log("The score is" + " " + playerScore + " " + "to" + " " + computerScore);99 updatedResult.textContent = "You won! Your opponent chose" + " " + "Paper" + " " + "which loses to" + " " + "Scizzors" + ".";100 updatedScores.textContent = "Your Score:" + " " + playerScore + " | " + "Computer'\s Score:" + " " + computerScore + " | " + "Draws:" + " " + drawScore;101 }102 if (roundResult.charAt(4) === 'l'){103 computerScore++;104 console.log("The score is" + " " + playerScore + " " + "to" + " " + computerScore);105 updatedResult.textContent = "You lost! Your opponent chose" + " " + "Rock" + " " + "which beats" + " " + "Scizzors" + ".";106 updatedScores.textContent = "Your Score:" + " " + playerScore + " | " + "Computer'\s Score:" + " " + computerScore + " | " + "Draws:" + " " + drawScore;107 }108 if (roundResult.charAt(0) === 'I'){109 drawScore++;110 console.log("No points added to either player. The current score is" + " " + playerScore + " " + "to" + " " + computerScore + ".");111 updatedResult.textContent = "It's a draw! No Points have been added. Your opponent also chose" + " " + "Scizzors" + ".";112 updatedScores.textContent = "Your Score:" + " " + playerScore + " | " + "Computer's Score:" + " " + computerScore + " | " + "Draws:" + " " + drawScore;113 }114 // Ends the game if either the player or computer reaches a score of 5115 if (playerScore === 5) {116 startRound.textContent = "The game has ended. You won! Refresh the page to play again."117 // Makes buttons disappear so you can't play anymore118 rockbtn.style.display = "none";119 paperbtn.style.display = "none";120 scizzorsbtn.style.display = "none";121 } else if (computerScore === 5){122 startRound.textContent = "The game has ended. You lost! Refresh the page to play again."123 124 // Makes buttons disappear so you can't play anymore125 rockbtn.style.display = "none";126 paperbtn.style.display = "none";127 scizzorsbtn.style.display = "none";128 } 129});130// Opponent chooses a hand shape using random number generator131function computerPlay(){132 randomNumber = Math.floor(Math.random()*3) + 1;133 if (randomNumber === 1) {134 return "rock";135 } else if (randomNumber === 2) {136 return "paper";137 } else {138 return "scizzors";139 }140}141// Stores the player and the opponent's hand shape:142function playRound(buttonClicked){143 let newcomputerSelection = computerPlay();144 let playerPrompt = buttonClicked;145 //console.log(playerPrompt);146 let playerSelectionLowerCase = playerPrompt.toLowerCase(); // Makes the prompt input case insensitive, the the rest of the function reads lower case strings.147 //console.log(playerSelectionLowerCase);148 if ((playerSelectionLowerCase === "rock" && newcomputerSelection === "paper") 149 || (playerSelectionLowerCase === "scizzors" && newcomputerSelection === "rock") 150 || (playerSelectionLowerCase === "paper" && newcomputerSelection === "scizzors")) {151 console.log("You lost! Your opponent chose" + " " + newcomputerSelection + " " + "which beats" + " " + playerSelectionLowerCase + ".");152 return "You lost! Your opponent chose" + " " + newcomputerSelection + " " + "which beats" + " " + playerSelectionLowerCase + ".";153 /* I had these two console.log lines to test and make sure that both the player and opponent's hands were being stored correctly in the function.154 console.log(playerSelectionLowerCase);155 console.log(newcomputerSelection); */156 } else if (playerSelectionLowerCase === newcomputerSelection){157 console.log("It's a draw! Your opponent also chose" + " " + newcomputerSelection + ".");158 return "It's a draw! Your opponent also chose" + " " + newcomputerSelection + ".";159 /* I had these two console.log lines to test and make sure that both the player and opponent's hands were being stored correctly in the function.160 console.log(playerSelectionLowerCase);161 console.log(newcomputerSelection); */162 } else if ((playerSelectionLowerCase === "rock" && newcomputerSelection === "scizzors") 163 || (playerSelectionLowerCase === "scizzors" && newcomputerSelection === "paper") 164 || (playerSelectionLowerCase === "paper" && newcomputerSelection === "rock")) {165 console.log("You won! Your opponent chose" + " " + newcomputerSelection + " " + "which loses to" + " " + playerSelectionLowerCase + ".");166 return "You won! Your opponent chose" + " " + newcomputerSelection + " " + "which loses to" + " " + playerSelectionLowerCase + ".";167 /* I had these two console.log lines to test and make sure that both the player and opponent's hands were being stored correctly in the function.168 console.log(playerSelectionLowerCase);169 console.log(newcomputerSelection); */170 } else {171 console.log("Please enter a valid option, the input must be 'rock', 'paper', or 'scizzors' only). This round will count as a draw.");172 return "Please enter a valid option, the input must be 'rock', 'paper', or 'scizzors' only). This round will count as a draw."173 /* I had these two console.log lines to test and make sure that both the player and opponent's hands were being stored correctly in the function.174 console.log(playerSelectionLowerCase);175 console.log(newcomputerSelection); */176 }177}178// FROM MY ORIGINAL ROCK PAPER SCIZZORS PROJECT, DO NOT USE IN THIS REVISITED VERSION!179// function game() {180// // Start player's scores at 0.181 182// let roundOne = playRound();183// console.log(roundOne); // Lets you know how you won, lost, or drew the round.184// // Round 1185// if (roundOne.charAt(4) === 'w'){ // This is used to recognize the outcome from the playRound(); function.186// playerScore++;187// console.log("Round 1: The score is" + " " + playerScore + " " + "to" + " " + computerScore);188// }189// if (roundOne.charAt(4) === 'l'){190// computerScore++;191// console.log("Round 1: The score is" + " " + playerScore + " " + "to" + " " + computerScore);192// }193// if (roundOne.charAt(0) === 'I'){194// console.log("Round 1: No points added to either player. The current score is" + " " + playerScore + " " + "to" + " " + computerScore + ".");195// }196// if (roundOne.charAt(0) === 'P'){197// console.log("Round 1: No points added to either player. The current score is" + " " + playerScore + " " + "to" + " " + computerScore + ".");198// }199 200// //Round 2201// let roundTwo = playRound();202// console.log(roundTwo);203// if (roundTwo.charAt(4) === 'w'){204// playerScore++;205// console.log("Round 2: The score is" + " " + playerScore + " " + "to" + " " + computerScore);206// }207// if (roundTwo.charAt(4) === 'l'){208// computerScore++;209// console.log("Round 2: The score is" + " " + playerScore + " " + "to" + " " + computerScore);210// }211// if (roundTwo.charAt(0) === 'I'){212// console.log("Round 2: No points added to either player. The current score is" + " " + playerScore + " " + "to" + " " + computerScore + ".");213// }214// if (roundTwo.charAt(0) === 'P'){215// console.log("Round 2: No points added to either player. The current score is" + " " + playerScore + " " + "to" + " " + computerScore + ".");216// }217// // Round 3218// let roundThree = playRound();219// console.log(roundThree);220// if (roundThree.charAt(4) === 'w'){221// playerScore++;222// console.log("Round 3: The score is" + " " + playerScore + " " + "to" + " " + computerScore);223// }224// if (roundThree.charAt(4) === 'l'){225// computerScore++;226// console.log("Round 3: The score is" + " " + playerScore + " " + "to" + " " + computerScore);227// }228// if (roundThree.charAt(0) === 'I'){229// console.log("Round 3: No points added to either player. The current score is" + " " + playerScore + " " + "to" + " " + computerScore + ".");230// }231// if (roundThree.charAt(0) === 'P'){232// console.log("Round 3: No points added to either player. The current score is" + " " + playerScore + " " + "to" + " " + computerScore + ".");233// }234// //Round 4235// let roundFour = playRound();236// console.log(roundFour);237// if (roundFour.charAt(4) === 'w'){238// playerScore++;239// console.log("Round 4: The score is" + " " + playerScore + " " + "to" + " " + computerScore);240// }241// if (roundFour.charAt(4) === 'l'){242// computerScore++;243// console.log("Round 4: The score is" + " " + playerScore + " " + "to" + " " + computerScore);244// }245// if (roundFour.charAt(0) === 'I'){246// console.log("Round 4: No points added to either player. The current score is" + " " + playerScore + " " + "to" + " " + computerScore + ".");247// }248 249// if (roundFour.charAt(0) === 'P'){250// console.log("Round 4: No points added to either player. The current score is" + " " + playerScore + " " + "to" + " " + computerScore + ".");251// }252// //Round 5253// let roundFive = playRound();254// console.log(roundFive);255// if (roundFive.charAt(4) === 'w'){256// playerScore++;257// console.log("Round 5: The final score is" + " " + playerScore + " " + "to" + " " + computerScore);258// }259// if (roundFive.charAt(4) === 'l'){260// computerScore++;261// console.log("Round 5: The final score is" + " " + playerScore + " " + "to" + " " + computerScore);262// }263// if (roundFive.charAt(0) === 'I'){264// console.log("Round 5: No points added to either player. The final score is" + " " + playerScore + " " + "to" + " " + computerScore + ".");265// }266// if (roundFive.charAt(0) === 'P'){267// console.log("Round 5: No points added to either player. The current score is" + " " + playerScore + " " + "to" + " " + computerScore + ".");268// }269// if (playerScore > computerScore) {270// return "You won the game of 5! The game is now complete, thanks for playing!"271// } else if (playerScore < computerScore) {272// return "You lost the game of 5! The game is now complete, thanks for playing!"273// } else {274// return "It's a draw! The game is now complete, thanks for playing!"275// }...
stat.js
Source:stat.js
1import Mock from 'mockjs';2const AllStats = [3 {4 studentno: '2011360114',5 examno: '20110511',6 studentname: 'å¼ æ£å',7 class: 'å
年级 ï¼5) ç',8 subjectScores: {9 score: '82.5',10 classRank: '4',11 gradeRank: '14',12 rank: 'A+'13 },14 totalScores: {15 score: '273.5',16 classRank: '1',17 gradeRank: '1',18 rank: 'A+'19 }20 },21 {22 studentno: '2011360115',23 examno: '20110512',24 studentname: 'åé£',25 class: 'å
年级 ï¼6) ç',26 subjectScores: {27 score: '87.5',28 classRank: '3',29 gradeRank: '8',30 rank: 'A+'31 },32 totalScores: {33 score: '281.5',34 classRank: '1',35 gradeRank: '1',36 rank: 'A+'37 }38 },39 {40 studentno: '2011360116',41 examno: '20110513',42 studentname: 'ç½å¥½è±',43 class: 'å
年级 ï¼7) ç',44 subjectScores: {45 score: '65.5',46 classRank: '7',47 gradeRank: '24',48 rank: 'B+'49 },50 totalScores: {51 score: '225.5',52 classRank: '3',53 gradeRank: '3',54 rank: 'B+'55 }56 },57 {58 studentno: '2011360117',59 examno: '20110514',60 studentname: 'æè¿å',61 class: 'å
年级 ï¼8) ç',62 subjectScores: {63 score: '76.5',64 classRank: '3',65 gradeRank: '16',66 rank: 'A+'67 },68 totalScores: {69 score: '243.5',70 classRank: '2',71 gradeRank: '2',72 rank: 'B+'73 }74 },75 {76 studentno: '2011360118',77 examno: '20110515',78 studentname: 'å¶æ',79 class: 'å
年级 ï¼9) ç',80 subjectScores: {81 score: '78.5',82 classRank: '2',83 gradeRank: '11',84 rank: 'A+'85 },86 totalScores: {87 score: '267.5',88 classRank: '1',89 gradeRank: '1',90 rank: 'A+'91 }92 }93];94const PersonStats = [95 {96 title: 'æåå(2018360247)个人æ绩å',97 scores: [98 {99 examname: '2016å¦å¹´ä¸å¦æ ææ«èè¯',100 subjectScores: [101 {102 dictname: 'è¯æ',103 score: '90'104 },105 {106 dictname: 'æ°å¦',107 score: '95'108 },109 {110 dictname: 'è±æ',111 score: '85'112 },113 {114 dictname: 'åå¦',115 score: '89.5'116 },117 {118 dictname: 'ç©ç',119 score: '90'120 }121 ],122 totalScore: '485.5'123 },124 {125 examname: '2017å¦å¹´ä¸å¦æ ææ«èè¯',126 subjectScores: [127 {128 dictname: 'è¯æ',129 score: '75'130 },131 {132 dictname: 'æ°å¦',133 score: '80'134 },135 {136 dictname: 'è±æ',137 score: '90'138 },139 {140 dictname: 'åå¦',141 score: '90.5'142 },143 {144 dictname: 'ç©ç',145 score: '80'146 }147 ],148 totalScore: '467.5'149 },150 {151 examname: '2018å¦å¹´ä¸å¦æ ææ«èè¯',152 subjectScores: [153 {154 dictname: 'è¯æ',155 score: '90'156 },157 {158 dictname: 'æ°å¦',159 score: '95'160 },161 {162 dictname: 'è±æ',163 score: '85'164 },165 {166 dictname: 'åå¦',167 score: '89.5'168 },169 {170 dictname: 'ç©ç',171 score: '90'172 }173 ],174 totalScore: '485.5'175 },176 {177 examname: '2019å¦å¹´ä¸å¦æ ææ«èè¯',178 subjectScores: [179 {180 dictname: 'è¯æ',181 score: '90'182 },183 {184 dictname: 'æ°å¦',185 score: '95'186 },187 {188 dictname: 'è±æ',189 score: '85'190 },191 {192 dictname: 'åå¦',193 score: '89.5'194 },195 {196 dictname: 'ç©ç',197 score: '90'198 }199 ],200 totalScore: '485.5'201 },202 {203 examname: '2020å¦å¹´ä¸å¦æ ææ«èè¯',204 subjectScores: [205 {206 dictname: 'è¯æ',207 score: '90'208 },209 {210 dictname: 'æ°å¦',211 score: '95'212 },213 {214 dictname: 'è±æ',215 score: '85'216 },217 {218 dictname: 'åå¦',219 score: '89.5'220 },221 {222 dictname: 'ç©ç',223 score: '90'224 }225 ],226 totalScore: '485.5'227 }228 ]229 },230 {231 title: 'æè¿å(2018360247)个人æ绩å',232 scores: [233 {234 examname: '2016å¦å¹´ä¸å¦æ ææ«èè¯',235 subjectScores: [236 {237 dictname: 'è¯æ',238 score: '90'239 },240 {241 dictname: 'æ°å¦',242 score: '95'243 },244 {245 dictname: 'è±æ',246 score: '85'247 },248 {249 dictname: 'åå¦',250 score: '89.5'251 },252 {253 dictname: 'ç©ç',254 score: '90'255 }256 ],257 totalScore: '485.5'258 },259 {260 examname: '2017å¦å¹´ä¸å¦æ ææ«èè¯',261 subjectScores: [262 {263 dictname: 'è¯æ',264 score: '90'265 },266 {267 dictname: 'æ°å¦',268 score: '95'269 },270 {271 dictname: 'è±æ',272 score: '85'273 },274 {275 dictname: 'åå¦',276 score: '89.5'277 },278 {279 dictname: 'ç©ç',280 score: '90'281 }282 ],283 totalScore: '485.5'284 },285 {286 examname: '2018å¦å¹´ä¸å¦æ ææ«èè¯',287 subjectScores: [288 {289 dictname: 'è¯æ',290 score: '90'291 },292 {293 dictname: 'æ°å¦',294 score: '95'295 },296 {297 dictname: 'è±æ',298 score: '85'299 },300 {301 dictname: 'åå¦',302 score: '89.5'303 },304 {305 dictname: 'ç©ç',306 score: '90'307 }308 ],309 totalScore: '485.5'310 },311 {312 examname: '2019å¦å¹´ä¸å¦æ ææ«èè¯',313 subjectScores: [314 {315 dictname: 'è¯æ',316 score: '90'317 },318 {319 dictname: 'æ°å¦',320 score: '95'321 },322 {323 dictname: 'è±æ',324 score: '85'325 },326 {327 dictname: 'åå¦',328 score: '89.5'329 },330 {331 dictname: 'ç©ç',332 score: '90'333 }334 ],335 totalScore: '485.5'336 },337 {338 examname: '2020å¦å¹´ä¸å¦æ ææ«èè¯',339 subjectScores: [340 {341 dictname: 'è¯æ',342 score: '90'343 },344 {345 dictname: 'æ°å¦',346 score: '95'347 },348 {349 dictname: 'è±æ',350 score: '85'351 },352 {353 dictname: 'åå¦',354 score: '89.5'355 },356 {357 dictname: 'ç©ç',358 score: '90'359 }360 ],361 totalScore: '485.5'362 }363 ]364 },365 {366 title: 'æé©(2018360247)个人æ绩å',367 scores: [368 {369 examname: '2018å¦å¹´ä¸å¦æ ææ«èè¯',370 subjectScores: [371 {372 dictname: 'è¯æ',373 score: '90'374 },375 {376 dictname: 'æ°å¦',377 score: '95'378 },379 {380 dictname: 'è±æ',381 score: '85'382 },383 {384 dictname: 'åå¦',385 score: '89.5'386 },387 {388 dictname: 'ç©ç',389 score: '90'390 }391 ],392 totalScore: '485.5'393 },394 {395 examname: '2019å¦å¹´ä¸å¦æ ææ«èè¯',396 subjectScores: [397 {398 dictname: 'è¯æ',399 score: '90'400 },401 {402 dictname: 'æ°å¦',403 score: '95'404 },405 {406 dictname: 'è±æ',407 score: '85'408 },409 {410 dictname: 'åå¦',411 score: '89.5'412 },413 {414 dictname: 'ç©ç',415 score: '90'416 }417 ],418 totalScore: '485.5'419 },420 {421 examname: '2020å¦å¹´ä¸å¦æ ææ«èè¯',422 subjectScores: [423 {424 dictname: 'è¯æ',425 score: '90'426 },427 {428 dictname: 'æ°å¦',429 score: '95'430 },431 {432 dictname: 'è±æ',433 score: '85'434 },435 {436 dictname: 'åå¦',437 score: '89.5'438 },439 {440 dictname: 'ç©ç',441 score: '90'442 }443 ],444 totalScore: '485.5'445 },446 {447 examname: '2021å¦å¹´ä¸å¦æ ææ«èè¯',448 subjectScores: [449 {450 dictname: 'è¯æ',451 score: '90'452 },453 {454 dictname: 'æ°å¦',455 score: '95'456 },457 {458 dictname: 'è±æ',459 score: '85'460 },461 {462 dictname: 'åå¦',463 score: '89.5'464 },465 {466 dictname: 'ç©ç',467 score: '90'468 }469 ],470 totalScore: '485.5'471 },472 {473 examname: '2022å¦å¹´ä¸å¦æ ææ«èè¯',474 subjectScores: [475 {476 dictname: 'è¯æ',477 score: '90'478 },479 {480 dictname: 'æ°å¦',481 score: '95'482 },483 {484 dictname: 'è±æ',485 score: '85'486 },487 {488 dictname: 'åå¦',489 score: '89.5'490 },491 {492 dictname: 'ç©ç',493 score: '90'494 }495 ],496 totalScore: '485.5'497 }498 ]499 }500];...
main.js
Source:main.js
1function getValues(){2 let player1_joker = $(".player1 #joker-amt").val();3 let player2_joker = $(".player2 #joker-amt").val();4 let player3_joker = $(".player3 #joker-amt").val();5 let player4_joker = $(".player4 #joker-amt").val();6 let jv = $("#joker-value").val();7 let player1_placement = $(".player1 #place").val();8 let player2_placement = $(".player2 #place").val();9 let player3_placement = $(".player3 #place").val();10 let player4_placement = $(".player4 #place").val();11 calcAll(player1_joker,player2_joker,player3_joker,player4_joker,player1_placement,player2_placement,player3_placement,player4_placement,jv)12 updateTotalScore()13}14var player1_score = 0;15var player2_score = 0;16var player3_score = 0;17var player4_score = 0;18function updateTotalScore(){19 $(".total-score .player1").html(Math.round(player1_score*100)/100);20 $(".total-score .player2").html(Math.round(player2_score*100)/100);21 $(".total-score .player3").html(Math.round(player3_score*100)/100);22 $(".total-score .player4").html(Math.round(player4_score*100)/100);23}24function calcAll(p1_j,p2_j,p3_j,p4_j,p1_p,p2_p,p3_p,p4_p,j_val){25 let lose_first = 4.5;26 let lose_second = -1;27 let lose_third = -1.5;28 let lose_forth = -2;29 let joker_value = parseFloat(j_val);30 let p1_joker = (parseFloat(p1_j) * joker_value);31 let p2_joker = (parseFloat(p2_j) * joker_value);32 let p3_joker = (parseFloat(p3_j) * joker_value);33 let p4_joker = (parseFloat(p4_j) * joker_value);34 let p1_placement = p1_p;35 let p2_placement = p2_p;36 let p3_placement = p3_p;37 let p4_placement = p4_p;38 //Player 1 earns Joker39 player1_score += p1_joker * 3;40 player2_score -= p1_joker;41 player3_score -= p1_joker;42 player4_score -= p1_joker;43 //Player 2 earns Joker44 player1_score -= p2_joker;45 player2_score += p2_joker * 3;46 player3_score -= p2_joker;47 player4_score -= p2_joker;48 //Player 3 earns Joker49 player1_score -= p3_joker;50 player2_score -= p3_joker;51 player3_score += p3_joker * 3;52 player4_score -= p3_joker;53 //Player 4 earns Joker54 player1_score -= p4_joker;55 player2_score -= p4_joker;56 player3_score -= p4_joker;57 player4_score += p4_joker * 3;58 if(p1_placement == "win"){59 player1_score += 6;60 player2_score -= 2;61 player3_score -= 2;62 player4_score -= 2;63 }else if(p2_placement == "win"){64 player1_score -= 2;65 player2_score += 6;66 player3_score -= 2;67 player4_score -= 2;68 }else if(p3_placement == "win"){69 player1_score -= 2;70 player2_score -= 2;71 player3_score += 6;72 player4_score -= 2;73 }else if(p4_placement == "win"){74 player1_score -= 2;75 player2_score -= 2;76 player3_score -= 2;77 player4_score += 6;78 }else if(p1_placement == "lose" || p2_placement == "lose" || p3_placement == "lose" || p4_placement == "lose"){79 switch (p1_placement){80 case "lose":81 player1_score += lose_forth;82 break;83 case "3":84 player1_score += lose_third;85 break;86 case "2":87 player1_score += lose_second;88 break;89 case "1":90 player1_score += lose_first;91 break;92 }93 switch (p2_placement){94 case "lose":95 player2_score += lose_forth;96 break;97 case "3":98 player2_score += lose_third;99 break;100 case "2":101 player2_score += lose_second;102 break;103 case "1":104 player2_score += lose_first;105 break;106 }107 switch (p3_placement){108 case "lose":109 player3_score += lose_forth;110 break;111 case "3":112 player3_score += lose_third;113 break;114 case "2":115 player3_score += lose_second;116 break;117 case "1":118 player3_score += lose_first;119 break;120 }121 switch (p4_placement){122 case "lose":123 player4_score += lose_forth;124 break;125 case "3":126 player4_score += lose_third;127 break;128 case "2":129 player4_score += lose_second;130 break;131 case "1":132 player4_score += lose_first;133 break;134 }135 }else{136 switch (p1_placement){137 case "4":138 player1_score -= 1.5;139 break;140 case "3":141 player1_score -= 1;142 break;143 case "2":144 player1_score -= 0.5;145 break;146 case "1":147 player1_score += 3;148 break;149 }150 switch (p2_placement){151 case "4":152 player2_score -= 1.5;153 break;154 case "3":155 player2_score -= 1;156 break;157 case "2":158 player2_score -= 0.5;159 break;160 case "1":161 player2_score += 3;162 break;163 }164 switch (p3_placement){165 case "4":166 player3_score -= 1.5;167 break;168 case "3":169 player3_score -= 1;170 break;171 case "2":172 player3_score -= 0.5;173 break;174 case "1":175 player3_score += 3;176 break;177 }178 switch (p4_placement){179 case "4":180 player4_score -= 1.5;181 break;182 case "3":183 player4_score -= 1;184 break;185 case "2":186 player4_score -= 0.5;187 break;188 case "1":189 player4_score += 3;190 break;191 }192 }193 let p1_name = $(".player1 input").val();194 $(".player1 span").html(p1_name);195 $(".player1 input").css("display","none");196 let p2_name = $(".player2 input").val();197 $(".player2 span").html(p2_name);198 $(".player2 input").css("display","none");199 let p3_name = $(".player3 input").val();200 $(".player3 span").html(p3_name);201 $(".player3 input").css("display","none");202 let p4_name = $(".player4 input").val();203 $(".player4 span").html(p4_name);204 $(".player4 input").css("display","none");...
app.js
Source:app.js
1function logText(e) {2 console.log(this.classList.value);3 e.stopPropagation(); // stop bubbling!4 console.log(this);5}6const bulbasaur = document.querySelector('.bulbasaur');7const squirtle = document.querySelector('.squirtle');8const charmander = document.querySelector('.charmander');9bulbasaur.addEventListener('click', playRound)10squirtle.addEventListener('click', playRound)11charmander.addEventListener('click', playRound)12let playerScore = 0;13let compScore = 0;14let roundScore = 0;15// while (playerScore < 5 || compScore < 5) {16function playRound() {17 const myArray = ["bulbasaur", "squirtle", "charmander"];18 const computerSelection = computerPlay();19 let playerSelection = this.classList.value.toUpperCase();20 function computerPlay() {21 y = myArray[~~(Math.random() * myArray.length)].toUpperCase();22 return (y);23 }24 if (computerSelection === "BULBASAUR") {25 if (playerSelection === computerSelection) {26 playerScore = playerScore + 0;27 compScore = compScore + 0;28 roundScore = roundScore + 1;29 var result = ("Bulbasaur vs Bulbasaur, it's a TIE!")30 } else if (playerSelection === "SQUIRTLE") {31 playerScore = playerScore + 0;32 compScore = compScore + 1;33 roundScore = roundScore + 1;34 var result = ("Bulbasaur beats Squirtle, you LOSE!")35 } else {36 playerScore = playerScore + 1;37 compScore = compScore + 0;38 roundScore = roundScore + 1;39 var result = ("Charmander beats Bulbasaur, you WIN!")40 } 41 } else if (computerSelection === "CHARMANDER") {42 if (playerSelection === computerSelection) {43 roundScore = roundScore + 1;44 playerScore = playerScore + 0;45 compScore = compScore + 0;46 var result = ("Charmander vs Charmander, it's a TIE!")47 } else if (playerSelection === "BULBASAUR") {48 roundScore = roundScore + 1;49 playerScore = playerScore + 0;50 compScore = compScore + 1;51 var result = ("Charmander beats Bulbasaur, you Lose!")52 } else {53 roundScore = roundScore + 1;54 playerScore = playerScore + 1;55 compScore = compScore + 0;56 var result = ("Squirtle beats Charmander, you Win!")57 } 58 } else if (computerSelection === "SQUIRTLE") {59 if (playerSelection === computerSelection) {60 roundScore = roundScore + 1;61 playerScore = playerScore + 0;62 compScore = compScore + 0;63 var result = ("Squirtle vs Squirtle, it's a Tie!")64 } else if (playerSelection === "CHARMANDER") {65 roundScore = roundScore + 1;66 playerScore = playerScore + 0;67 compScore = compScore + 1;68 var result = ("Squirtle beats Charmander, You Lose!")69 } else {70 roundScore = roundScore + 1;71 playerScore = playerScore + 1;72 compScore = compScore + 0;73 var result = ("Bulbasaur beats Squirtle, You Win!")74 } 75 }76 console.log(result);77 console.log(roundScore);78 console.log('player score: ' + playerScore);79 console.log('computer score: ' + compScore);80 81 const resultContainer = document.querySelector('.resultContainer');82 83 resultContainer.innerText = "Round " + roundScore + "...FIGHT!" + "\r\n";84 resultContainer.innerText += result + "\r\n";85 resultContainer.innerText += "Player Score: " + playerScore + " vs Computer Score: " + compScore + "\r\n";86 if (playerScore === 5) {87 resultContainer.innerText += "\r\n YOU ARE THE WINNER!";88 roundScore = 0;89 playerScore = 0;90 compScore = 0;91 } else if (compScore === 5) {92 resultContainer.innerText += "\r\n COMPUTER WINS, you LOSE :(";93 roundScore = 0;94 playerScore = 0;95 compScore = 0;96 } 97}98document.getElementsByClassName("playerScore").innerHTML = playRound[0];99// }100// if (playerScore > compScore) {101// console.log("YOU WIN! :) you beat the computer by scoring "+playerScore +" while the computer only scored " + compScore)102// } else if (playerScore === compScore) {103// console.log("Ya'll Tie! The final score was "+ playerScore + " vs " + compScore)104// } else {105// console.log("YOU LOSE :(. The computer beat you by scoring " + compScore + " and you only scored " + playerScore)...
Blackjack-Game.py
Source:Blackjack-Game.py
1import random2import Logo3cards = [11,2,3,4,5,6,7,8,9,10,10,10,10]4def getCard():5 return random.choice(cards)6def addCardToUser():7 user_cards.append(getCard())8def addCardToComputer():9 computer_cards.append(getCard())10def sumOfCards(some_list):11 return sum(some_list)12def checkAce(score, some_list):13 if score > 21:14 if 11 in some_list:15 some_list.remove(11)16 some_list.append(1)17def checkWinner(user_score, computer_score):18 if user_score > 21:19 print("you Have Lost")20 elif computer_score > 21:21 print("you Have Win")22 elif user_score > computer_score :23 print("you have Win")24 elif computer_score > user_score :25 print("you have Lost")26 else:27 print("it's a Draw")28def printUserScore():29 print(f"your cards are : {user_cards} and your score is {user_score}")30def printComputerScore():31 print(f"the dealer Cards are : {computer_cards} and his score is {computer_score}")32def low(score, some_list):33 while score < 17 :34 some_list.append(getCard())35 score = sumOfCards(some_list)36 37 38user_score = 039computer_score = 040play = True 41answer = input("do you want to play 'y' for play and 'n' to exit : ") 42if answer == "n":43 play = False 44else:45 play = True 46while play:47 user_cards = []48 computer_cards = []49 print(Logo.logo)50 print("Welcome to My BlackJack Game!!!")51 addCardToUser() 52 addCardToUser()53 addCardToComputer()54 addCardToComputer()55 user_score= sumOfCards(user_cards)56 computer_score= sumOfCards(computer_cards)57 print(f"your cards are : {user_cards} and your score is {user_score}")58 print(f"the dealer first card is :{computer_cards[0]}")59 60 if (user_score == 21 or computer_score == 21) and (len(user_cards) == 2 or len(computer_cards) == 2):61 print("------------------------------")62 low(user_score, user_cards)63 low(computer_score, computer_cards)64 printUserScore()65 printComputerScore()66 checkWinner(user_score, computer_score)67 print("------------------------------")68 else:69 another=input("Please Enter a 'y' to get another card and 'n' to pass : ")70 if another == "y":71 addCardToUser()72 checkAce(user_score, user_cards)73 checkAce(computer_score, computer_cards)74 user_score= sumOfCards(user_cards)75 computer_score= sumOfCards(computer_cards)76 low(user_score, user_cards)77 low(computer_score, computer_cards)78 checkAce(user_score, user_cards)79 checkAce(computer_score, computer_cards)80 user_score= sumOfCards(user_cards)81 computer_score= sumOfCards(computer_cards)82 printUserScore()83 printComputerScore()84 checkWinner(user_score, computer_score)85 else:86 checkAce(user_score, user_cards)87 checkAce(computer_score, computer_cards)88 user_score= sumOfCards(user_cards)89 computer_score= sumOfCards(computer_cards)90 low(user_score, user_cards)91 low(computer_score, computer_cards)92 checkAce(user_score, user_cards)93 checkAce(computer_score, computer_cards)94 user_score= sumOfCards(user_cards)95 computer_score= sumOfCards(computer_cards)96 printUserScore()97 printComputerScore()98 checkWinner(user_score, computer_score)99 answer = input("do you want to play again 'y' for play and 'n' to exit : ") 100 if answer == "n":101 play = False 102 else:103 play = True104 105 ...
script.py
Source:script.py
1import random2import time3end_c = '\033[0;0m'4red = '\033[2;31;40m'5green = '\033[2;32;40m'6start = None7user_score = 08computer_score = 09def control(select):10 global user_score11 global computer_score12 if select == 1:13 generate = random.randint(1, 3)14 if generate == 1:15 print('YOU: Rock SCORE: ', user_score)16 print('FRIEND: Rock SCORE: ', computer_score)17 elif generate == 2:18 computer_score += 1019 print('YOU: Rock SCORE: ', user_score)20 print('FRIEND: Paper SCORE: ', computer_score)21 else:22 user_score += 1023 print('YOU: Rock SCORE: ', user_score)24 print('FRIEND: Scissor SCORE: ', computer_score)25 elif select == 2:26 generate = random.randint(1, 3)27 if generate == 1:28 user_score += 1029 print('YOU: Paper SCORE: ', user_score)30 print('FRIEND: Rock SCORE: ', computer_score)31 elif generate == 2:32 print('YOU: Paper SCORE: ', user_score)33 print('FRIEND: Paper SCORE: ', computer_score)34 else:35 computer_score += 1036 print('YOU: Paper SCORE: ', user_score)37 print('FRIEND: Scissor SCORE: ', computer_score)38 elif select == 3:39 generate = random.randint(1, 3)40 if generate == 1:41 computer_score += 1042 print('YOU: Scissor SCORE: ', user_score)43 print('FRIEND: Rock SCORE: ', computer_score)44 elif generate == 2:45 user_score += 1046 print('YOU: Scissor SCORE: ', user_score)47 print('FRIEND: Paper SCORE: ', computer_score)48 else:49 print('YOU: Scissor SCORE: ', user_score)50 print('FRIEND: Scissor SCORE: ', computer_score)51 else:52 print(f'{red}input Error{end_c}')53while start != 'no':54 tools = ['1.Rock', '2.Paper', '3.Scissor']55 for tool in tools:56 print(tool)57 check = int(input('Enter your choice: '))58 # Call to the control function59 control(check)60 prompt = f'Are you want to replay({green}yes{end_c}/{red}no{end_c}): '61 if computer_score == 100:62 print('You lose')63 start = input(prompt)64 time.sleep(0.2)65 print(f'{red}-{end_c}', end="")66 elif user_score == 100:67 print('You won')68 start = input(prompt)69 time.sleep(0.2)...
score.py
Source:score.py
1import re2class Member:3 def __init__(self):4 self.score_map = {'A': 0, 'B': 0, 'C': 0, 'D': 0}5 self.name = input('Input your mark:')6 def assess(self):7 self.score_map['A'] = int(input('Input A\'s score:'))8 self.score_map['B'] = int(input('Input B\'s score:'))9 self.score_map['C'] = int(input('Input C\'s score:'))10 self.score_map['D'] = int(input('Input D\'s score:'))11 def mat2map(self):12 mat = input('---%s $ Input AãBãCãD \'s scores:' % self.name)13 mat = re.split(r" +", mat)14 self.score_map['A'] = int(mat[0])15 self.score_map['B'] = int(mat[1])16 self.score_map['C'] = int(mat[2])17 self.score_map['D'] = int(mat[3])18print('-----Create 4 member:')19A, B, C, D = Member(), Member(), Member(), Member()20A.mat2map()21B.mat2map()22C.mat2map()23D.mat2map()24score = []25score.append(A.score_map['A']*0.1 + (B.score_map['A']+C.score_map['A']+D.score_map['A'])*0.3)26score.append(B.score_map['B']*0.1 + (A.score_map['B']+C.score_map['B']+D.score_map['B'])*0.3)27score.append(C.score_map['C']*0.1 + (B.score_map['C']+A.score_map['C']+D.score_map['C'])*0.3)28score.append(D.score_map['D']*0.1 + (B.score_map['D']+C.score_map['D']+A.score_map['D'])*0.3)29sum = 0.030for each in score:31 sum += each32retain = A.score_map['A']+A.score_map['B']+A.score_map['C']+A.score_map['D'] - sum33for i in range(len(score)):34 score[i] += (retain - retain % 4) / 435retain = retain % 436mi = 10037index = 038for i in range(len(score)):39 if mi > score[i]:40 mi = score[i]41 index = i42score[index] += retain...
Using AI Code Generation
1const { Pact } = require('@pact-foundation/pact');2const { like } = require('@pact-foundation/pact/dsl/matchers');3const { somethingLike } = require('@pact-foundation/pact/dsl/matchers');4const { eachLike } = require('@pact-foundation/pact/dsl/matchers');5const { term } = require('@pact-foundation/pact/dsl/matchers');6const { eachLike } = require('@pact-foundation/pact/dsl/matchers');7const { Matchers } = require('@pact-foundation/pact/dsl/matchers');8const { somethingLike } = require('@pact-foundation/pact/dsl/matchers');9const { eachLike } = require('@pact-foundation/pact/dsl/matchers');10const { term } = require('@pact-foundation/pact/dsl/matchers');11const { eachLike } = require('@pact-foundation/pact/dsl/matchers');12const { Matchers } = require('@pact-foundation/pact/dsl/matchers');13const { somethingLike } = require('@pact-foundation/pact/dsl/matchers');14const { eachLike } = require('@pact-foundation/pact/dsl/matchers');15const { term } = require('@pact-foundation/pact/dsl/matchers');16const { eachLike } = require('@pact-foundation/pact/dsl/matchers');17const { Matchers } = require('@pact-foundation/pact/dsl/matchers');18const { somethingLike } = require('@pact-foundation/pact/dsl/matchers');19const { eachLike } = require('@pact-foundation/pact/dsl/matchers');20const { term } = require('@pact-foundation/pact/dsl/matchers');21const { eachLike } = require('@pact-foundation/pact/dsl/matchers');22const { Matchers } = require('@pact-foundation/pact/dsl/matchers');23const { somethingLike } = require('@pact-foundation/pact/dsl/matchers');24const { eachLike } = require('@pact-foundation/pact/dsl/matchers');25const { term } = require('@pact-foundation/pact/dsl/matchers');26const { eachLike } = require('@pact-foundation/pact
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!