-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1564 lines (1456 loc) · 52.7 KB
/
index.html
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="capstone.css" type="text/css" />
<link rel="icon" href="./media/BL-web-pico.png" />
<meta property="og:title" content="Welcome to Brian Loveless .com" />
<meta
property="og:description"
content="A website to showcase my skills as a software engineer.
Brian Loveless
Javascript,
Html,
Css,
Java,
Python,
Software Engineering,
Computer Programming,
Full-Stack."
/>
<meta
name="description"
content="A website to showcase my projects and skills as a software engineer.
Brian Loveless
Javascript,
Html,
Css,
Java,
Python,
Software Engineering,
Computer Programming,
Full-Stack."
/>
<title>Code Compare</title>
<script
src="https://kit.fontawesome.com/70784aaaa8.js"
crossorigin="anonymous"
></script>
<script>
document.write("<style>#NoJS { display: none; }</style>");
</script>
</head>
<body>
<p id="NoJS">
Please enable JavaScript to use this page!
<noscript>
For full functionality of this site it is necessary to enable
JavaScript. Here are the
<a href="https://www.enable-javascript.com/">
instructions how to enable JavaScript in your web browser</a
>.
</noscript>
</p>
<script>
document.write("<p>JavaScript is enabled!</p>");
</script>
<h1 id="TOP" class="pageTitle">CODE COMPARE</h1>
<p class="scroll" id="scrollWordsJS"></p>
<p class="scroll" id="scrollWordsPY"></p>
<p class="scroll" id="scrollWordsJV"></p>
<h2>Have you ever wondered what computer coding is?</h2>
<h2>Have you thought there is no way I could ever do that?</h2>
<nav>
<h3>Take me to the games - I don't want to read these facts.</h3>
<a href="#TIP"> Tip Calculator</a> |
<a href="#PIG"> Pig Latin Translator</a> |
<a href="#RPS"> Rock Paper Scissors</a> |
<a href="#RPSLS"> Rock Paper Scissors Lizard Spock</a> |
<a href="#WTHR"> Weather Forecast</a> |
<a href="#DOG"> Random Dog Picture</a>
</nav>
<p>
This page is designed to help alleviate the stress and uncertainty of
those very questions. At its core computer code is simply 'instructions'
we programmers type for the computers to do certain 'tasks'. They can be
tasks with numbers or tasks with words or pictures or interacting with
other things on the internet or any combination of these things. While
Java, Python, and JavaScript are very different they also share many
things in common. Before we dive into the code let's explore these
languages. At first glance it would seem that the 3 biggest languages
currently used are as different as German, Mandarin, and Sanskrit. While
this may be true in some regards, upon a deeper understanding it is more
accurate to compare them to French, Spanish and Italian. While they have
different ways of doing the same things and slightly different
requirements to get there they have a lot in common.
</p>
<ul>
<li>
For this page
<a href="https://www.java.com/" target="_blank">Java</a> references Java
open JDK version 14 : 2020-03-17
</li>
<li>
<a href="https://www.python.org/" target="_blank">Python</a> references
Python 3.8.2 : 2020-02-25
</li>
<li>JavaScript refers to ECMAScript version 9</li>
</ul>
<div class="space"></div>
<div class="movie">
<iframe
width="650"
height="400"
src="https://www.youtube.com/embed/N7bLiAh1LZk"
frameborder="0"
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
></iframe>
</div>
<h1>Comparision facts</h1>
<div class="intro">
<p>
These languages are all very different but have similar ways of changing
numbers and words.
</p>
<ul>
<li>JavaScript</li>
<li>
<ul>
<li> </li>
<li>
Originally released with Netscape Navigator as LiveScript in 1995.
</li>
<li>
JavaScript is most known as the scripting language for Web pages
but used in many non-browser environments as well.
</li>
<li>In 2016 about 92% of all websites used JavaScript.</li>
<li>
JavaScript is high-level, multi-paradigm, and often just-in-time
compiled.
</li>
<li>
JavaScript enables interactive elements on web pages (like this
one).
</li>
<li>
JavaScript supports event-driven, imperative, and functional
programming styles.
</li>
<li> </li>
<!-- https://www.checkmarx.com/blog/javascript-history-infographic/
https://en.wikipedia.org/wiki/JavaScript
https://stackshare.io/stackups/java-vs-javascript-vs-python#description
https://developer.mozilla.org/en-US/docs/Web/JavaScript
-->
</ul>
</li>
<li>Python</li>
<li>
<ul>
<li> </li>
<li>
Python is an interpreted, high-level, general-purpose programming
language created by Guido Van Rossum in 1991.
</li>
<li>
Python is dynamically typed and garbage-collected. It supports
multiple programming paradigms, including structured
(particularly, procedural), object-oriented, and functional
programming.
</li>
<li>
Python is an open-source program meaning it is free to use by
anyone.
</li>
<li>
Python is an extensively used language by many top organizations
such as Dropbox, Quora, IBM, and CISCO.
</li>
<li>
Python is a cross-platform and highly portable language supporting
all major platforms.
</li>
<li> </li>
<!-- https://en.wikipedia.org/wiki/Python_(programming_language)
https://www.python.org/doc/-->
</ul>
</li>
<li>Java</li>
<li>
<ul>
<li> </li>
<li>
The initial name was 'OAK' and it was made by accident when James
Gosling and his team at SUN were building in C++ and wanted
something better.
</li>
<li>
Java is a programming language and computing platform first
released by Sun Microsystems in 1995. Development started around
1991 or 1992.
</li>
<li>
Java is class-based, object-oriented, and designed to have as few
implementation dependencies as possible.
</li>
<li>In a given year Java is downloaded roughly a billion times.</li>
<li>
Currently there are over 9 million Java developers globally.
</li>
<li>
In 2018 Indeed claimed they had 60,000 new positions for Java
programmers that year.
</li>
<li> </li>
<!-- https://en.wikipedia.org/wiki/Java_(programming_language)
https://www.oracle.com/java/technologies/-->
</ul>
</li>
</ul>
</div>
<h1>So what are developers saying about these languages?</h1>
<h3>
info below from
<a
href="https://stackshare.io/stackups/java-vs-javascript-vs-python"
target="_blank"
>
stack share</a
>
</h3>
<img
class="resp"
src="./media/titleBar.png"
alt="JavaScript Python and Java logos aligned with Java reporting 48.4k stacks, JavaScript reporting 102.6k stacks and Python reporting 65.7k stacks currently active."
/>
<h3>
On this site it seems that JavaScript is used about twice as much as
either Java or Python.
</h3>
<h3>
Since Java and Python files can run places besides websites they are
sometimes misrepresented in online code storage sites.
</h3>
<h2>Why do programmers like these languages?</h2>
<img
class="resp"
src="./media/whyChoose.png"
alt="infographic of why people like one of these language"
/>
<h3>
You can see all three are reported as having great libraries or frameworks
to incorporate shortcuts to common tasks.
</h3>
<h2>What do programmers dislike about these languages?</h2>
<img
class="resp"
src="./media/whyBad.png"
alt="infographic of why java python and javascript are 'bad'"
/>
<h3>There is just no way to make everyone happy all the time.</h3>
<h1>
According to GitHub's
<a href="https://octoverse.github.com/" target="_blank"
>State of the Octoverse</a
>
from September 2019.
</h1>
<h2>
Of the 350 plus languages on its site, JavaScript is the most popular
followed by Python and then Java.
</h2>
<h2>
More than 40 million developers are using GitHub and 10 million were new
in 2019.
</h2>
<img
id="modalChart"
src="./media/topLanguagesonGitHub.png"
alt="chart showing JavaScript top language on github followed by Python second and Java third"
style="width: 100%; max-width: 570px"
/>
<div id="myModal" class="modal">
<span class="close">×</span>
<img
src="./media/topLanguagesonGitHub.png"
class="modal-content"
id="img01"
alt="full screen version of chart above"
/>
<div id="caption"></div>
</div>
<h1 id="TIP">
For all the likes, dislikes and all the differences these languages have,
essentially they can similarly change numbers and words to make fantastic
things happen on your computer screen.
</h1>
<h2>
Let's take a look at how they perform some basic math for us with a tip
calculator.
</h2>
<h3>
I remember growing up my parents had a small credit card-sized table with
a 15% and 20% tip for amounts from $20 - $100 on it. But what if your bill
was outside that range or you wanted to leave something besides 15% or
20%? Bookmark this site to have your own quick calculator handy.
</h3>
<div>
<h3 class="vidlink">
<a target="_blank" href="https://www.youtube.com/watch?v=hlLK2NpTBhQ&t"
>Link to Tip Calc Demo Video Series</a
>
</h3>
<h3 class="vidlink">
<a target="_blank" href="https://brianlovega.github.io/demopagefortipcalc/"
>Link to Tip Calc Demo Site (the orange one from the videos)</a
>
</h3>
</div>
<div class="tip">
<h1>Tip calculator:</h1>
<h2>How much do I leave for a tip?</h2>
<form>
<h3>Input the info and click the try me tip button below to see.</h3>
<br />
<h4>
Amount of bill:
<input type="number" id="billAmount" placeholder="Bill amount" />
</h4>
<h4>
Tip percent :
<input type="number" id="tipPercent" placeholder="Percent to tip" />
</h4>
<br />
<button id="billset" onclick="setBill()">Try me tip</button>
<br />
<div class="align">
<div id="tipAmount"></div>
</div>
</form>
</div>
<h3>
Manipulating numbers and other math tasks are easily and quickly done by
computers.
</h3>
<div class="jscode">
<figure>
<figcaption>JavaScript code used on this site.</figcaption>
<pre class="prettyprint">
<code>
// bill tip
function setBill() {
let bill = document.getElementById("billAmount").value;
let tip = document.getElementById("tipPercent").value;
let amount = 0;
amount = bill * (tip / 100);
console.log(amount);
clean = "Tip amount : $ " + (Math.round(amount*100)/100).toFixed(2);
let answer = document.getElementById("tipAmount");
answer.textContent = clean;
}
// to stop page re-load while clicking 'Try me tip'
document.getElementById("billset").addEventListener("click", function (event) {
event.preventDefault();
});
</code>
</pre>
</figure>
</div>
<h2>
How you could implement the same in a Python command-line application.
</h2>
<div class="pycode">
<figure>
<figcaption>Python code here</figcaption>
<pre class="prettyprint">
<code>
import sys
while True:
print("welcome to tip clac enter the bill amount or q to exit")
bill = input()
if (bill == "q"):
sys.exit()
print("enter the percent to tip or q to exit")
percent = input()
if (percent == "q"):
sys.exit()
total = (float(percent)/100)* float(bill)
print(" for a bill of $" +bill +" tipping "+ percent +"% = $")
print(round(total, 2))
print("run again? (y)es or (q) q for quit")
again = input()
if (again == 'q'):
sys.exit()
</code>
</pre>
</figure>
</div>
<div class="javacode">
<figure>
<figcaption>
How you could implement through Java command-line application.
</figcaption>
<pre class="prettyprint">
<code>
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.*;
public class Main {
public static void main(String[] args) {
// write your code here
double bill = 0.00;
double tip = 0.00;
double amount = 0.00;
Scanner input = new Scanner(System.in);
boolean running = true;
while (running) {
print("Welcome to tip calc ... please input the bill amount");
bill = Double.parseDouble(input.nextLine().trim());
print("enter the percent you want to tip as a whole number");
tip = Double.parseDouble(input.nextLine().trim());
amount = bill * (tip / 100);
DecimalFormat df = new DecimalFormat("#.##");
df.setRoundingMode(RoundingMode.CEILING);
print(" for the bill $" + bill + " & tipping " + tip + " % = $" + df.format(amount) + " for the tip.");
print(" use again ? (y)es or (n)o ?");
String again = input.nextLine().toLowerCase();
if (again.startsWith("n")) {
running = false;
break;
}
}
}
public static void print(Object _O) {
System.out.println(_O);
}
}
</code>
</pre>
</figure>
</div>
<nav>
<h3>take me somewhere else</h3>
<a href="#TOP"> Top of page</a> |
<a href="#RPS"> Rock Paper Scissors</a> |
<a href="#RPSLS"> Rock Paper Scissors Lizard Spock</a> |
<a href="#WTHR">Weather Forecast</a> |
<a href="#DOG">Random Dog Picture</a>
</nav>
<h1 id="PIG">Pig Latin</h1>
<h2>It's not just numbers, you can modify words too.</h2>
<div class="pig">
<h3>Enter a word or phrase to pig latinize below.</h3>
<input
class="pigInput"
type="text"
id="pigWordIn"
placeholder="word or phrase to Pig Latin-ify"
/>
<button id="pigLatinBtn" onclick="piglatinize()">Try Me PL</button>
<div class="pigWord" id="pigWordOut"></div>
<h3>
Being able to change words referred to in all 3 languages as 'strings'
is an essential skill in coding.
</h3>
</div>
<div class="jscode">
<figure>
<figcaption>The JavaScript code used on this page here</figcaption>
<pre class="prettyprint">
<code>
function piglatinize() {
wordIn = document.getElementById("pigWordIn").value;
console.log(wordIn);
plWord = document.getElementById("pigWordOut");
let words = wordIn.split(" "),
newWords = [];
for (var i = 0; i < words.length; i++) {
newWords.push(this.translate(words[i]));
}
plWord.textContent = newWords.join(" ");
}
function translate(word) {
let array = word.split(""),
vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"],
newWord = "";
for (var y = 0; y < word.length; y++) {
if (vowels.includes(word[y])) {
if (y === 0) {
return word + "yay";
}
return word.slice(y, word.length) + word.slice(0, y) + "ay";
}
}
}
// to stop page re-load on click pig latin
document
.getElementById("pigLatinBtn")
.addEventListener("click", function (event) {
event.preventDefault();
});
</code>
</pre>
</figure>
</div>
<div class="pycode">
<figure>
<figcaption>
The site geeks for geeks has this refactored example for Python
</figcaption>
<pre class="prettyprint">
<code>
# Python program to encode a word to a Pig Latin.
def isVowel(c):
return (c == 'A' or c == 'E' or c == 'I' or
c == 'O' or c == 'U' or c == 'a' or
c == 'e' or c == 'i' or c == 'o' or
c == 'u');
def pigLatin(s):
# the index of the first vowel is stored.
length = len(s);
index = -1;
for i in range(length):
if (isVowel(s[i])):
index = i;
break;
# Pig Latin is possible only if vowels
# is present
if (index == -1):
return "-1";
# Take all characters after index (including
# index). Append all characters which are before
# index. Finally append "ay"
return s[index:] + s[0:index] + "ay";
str = pigLatin("graphic");
if (str == "-1"):
print("No vowels found. Pig Latin not possible");
else:
print(str);
# This code contributed by Rajput-Ji
</code>
</pre>
</figure>
</div>
<div class="javacode">
<figure>
<figcaption>
The site geeks for geeks has this refactored example for Java
</figcaption>
<pre class="prettyprint">
<code>
// Java program to encode a word to a Pig Latin.
class GFG {
static boolean isVowel(char c) {
return (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U' ||
c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
}
static String pigLatin(String s) {
// the index of the first vowel is stored.
int len = s.length();
int index = -1;
for (int i = 0; i < len; i++)
{
if (isVowel(s.charAt(i))) {
index = i;
break;
}
}
// Pig Latin is possible only if vowels
// is present
if (index == -1)
return "-1";
// Take all characters after index (including
// index). Append all characters which are before
// index. Finally append "ay"
return s.substring(index) +
s.substring(0, index) + "ay";
}
// Driver code
public static void main(String[] args) {
String str = pigLatin("graphic");
if (str == "-1")
System.out.print("No vowels found." +
"Pig Latin not possible");
else
System.out.print(str);
}
}
// This code is contributed by Anant Agarwal.
</code>
</pre>
</figure>
</div>
<nav>
<h3>take me somewhere else</h3>
<a href="#TOP"> Top of page</a>| <a href="#TIP"> Tip Calculator</a>|
<a href="#RPSLS"> Rock Paper Scissors Lizard Spock</a>|
<a href="#WTHR">Weather Forecast</a> |
<a href="#DOG">Random Dog Picture</a>
</nav>
<h3 id="RPS">
Now that you can change numbers and change words you can grow these lines
of code into something more advanced like a game. Click or touch an icon
to choose your weapon and then click on the 'Play RPS' button for a quick
round of the classic Rock Paper Scissors.
</h3>
<h1>rps</h1>
<div class="interactive">
<div class="options">
<div class="game" id="rockChoice">
Rock<i class="far fa-hand-rock fa-3x"></i>
</div>
<div class="game" id="paperChoice">
Paper<i class="far fa-hand-paper fa-3x"></i>
</div>
<div class="game" id="scissorChoice">
Scissors<i class="far fa-hand-scissors fa-3x"></i>
</div>
</div>
<div class="gameBoardRPS">
<h2>your move :</h2>
<div class="yourChoice" id="player">choice</div>
<button class="rpsBtn" id="playRPS">PLAY R P S</button>
<h2>computer chose :</h2>
<div class="compChoice" id="opponet">rock</div>
</div>
<div id="outcome"></div>
</div>
<div class="jscode">
<figure>
<figcaption>JavaScript code used on this page here</figcaption>
<pre class="prettyprint">
<code>
// rps
// access the html
let playerChose = document.getElementById("player");
let playerMove = "pick";
playerChose.innerText = playerMove;
// player / you pick rock
let rockChosen = document.getElementById("rockChoice");
rockChosen.addEventListener("click", rockChoice);
function rockChoice() {
playerChose.innerText = "ROCK";
playerMove = "rock";
}
// player / you pick paper
let paperChosen = document.getElementById("paperChoice");
paperChosen.addEventListener("click", paperChoice);
function paperChoice() {
playerChose.innerText = "PAPER";
playerMove = "paper";
}
// player / you pick scissor
let scissorChosen = document.getElementById("scissorChoice");
scissorChosen.addEventListener("click", scissorChoice);
function scissorChoice() {
playerChose.innerText = "SCISSORS";
playerMove = "scissors";
}
// computers move random number 0 1 or 2
function opponetMove() {
switch (Math.floor(Math.random() * 3)) {
case 0:
return "rock";
case 1:
return "paper";
case 2:
return "scissors";
}
}
// the button
let play = document.getElementById("playRPS");
play.addEventListener("click", rps);
// display computers choice
let opponet = document.getElementById("opponet");
// the game
function rps(e) {
// keep window open don't re-load page
e.preventDefault();
if (playerChose.innerText === "pick") {
alert("please choose rock paper or scissors first");
} else {
// run the function when click so we get a different choice every click
let om = opponetMove();
// update html
opponet.innerText = om;
// display win lose or draw
winner(playerMove, om);
return om;
}
}
// html access
let outcome = document.getElementById("outcome");
// outcomes logic
function winner(playerMove, om) {
if (playerMove == om) {
outcome.innerText = "Tie";
} else if (playerMove == "rock" && om == "paper") {
outcome.innerText = "you lose";
} else if (playerMove == "paper" && om == "scissors") {
outcome.innerText = "you lose";
} else if (playerMove == "scissors" && om == "rock") {
outcome.innerText = "you lose";
} else {
outcome.innerText = "you WIN !";
}
}
//////////////////////////
</code>
</pre>
</figure>
</div>
<div class="pycode">
<figure>
<figcaption>Python version of the same rps game</figcaption>
<pre class="prettyprint">
<code>
import random
import sys
wins = 0
losses = 0
ties = 0
while True: # The main game loop.
print('%s Wins, %s Losses, %s Ties' % (wins, losses, ties))
while True: # The player input loop.
print('Enter your move: (ro)ck (pa)per (sc)issors or (q)uit')
playerMove = input()
if playerMove == 'q':
print('thanks for playing your final score was: ')
print('%s Wins, %s Losses, %s Ties' % (wins, losses, ties))
sys.exit() # Quit the program.
if playerMove in['ro','pa','sc'] :
break # Break out of the player input loop.
print('Type one of ro, pa, sc, or q.')
# Display what the player chose:
if playerMove == 'ro':
print('ROCK versus...')
elif playerMove == 'pa':
print('PAPER versus...')
elif playerMove == 'sc':
print('SCISSORS versus...')
# Display what the computer chose:
randomNumber = random.randint(1, 5)
if randomNumber == 1:
computerMove = 'ro'
print('ROCK')
elif randomNumber == 2:
computerMove = 'pa'
print('PAPER')
elif randomNumber == 3:
computerMove = 'sc'
print('SCISSORS')
# Display and record the win/loss/tie:
# start with a tie
if playerMove == computerMove:
print('It is a tie!')
ties = ties + 1
# Win
elif playerMove == 'ro' and computerMove == 'sc':
print('You win! rock crushes scissors')
wins = wins + 1
elif playerMove == 'pa' and computerMove == 'ro':
print('You win! paper covers rock')
wins = wins + 1
elif playerMove == 'sc' and computerMove == 'pa':
print('You win! scissors cuts paper')
wins = wins + 1
# lose
elif playerMove == 'ro' and computerMove == 'pa':
print('You lose! computer paper covered your rock')
losses = losses + 1
elif playerMove == 'pa' and computerMove == 'sc':
print('You lose! computer scissors cut your paper')
losses = losses + 1
elif playerMove == 'sc' and computerMove == 'ro':
print('You lose! computer rock smashed your scissors')
losses = losses + 1
</code>
</pre>
</figure>
</div>
<div class="javacode">
<figure>
<figcaption>Java version here</figcaption>
<pre class="prettyprint">
<code>
import java.util.*;
public class Main {
private static void print(Object o) {
System.out.println(o);
}
public static void main(String[] args) {
// Brian's code for simple rock paper scissors
Scanner input = new Scanner(System.in); // Object for getting input from user keyboard
Random myRand = new Random(); // Object for Generating Random Numbers for comp move
// weapons
int RO = 0; // = Rock
int PA = 1; // = Paper
int SC = 2; // = Scissors
// variables
int user_choice; // User's Choice
int machine_choice; // Computer's Choice
boolean keep_playing = true;
int wins = 0;
int losses = 0;
int ties = 0;
// gameplay
while (keep_playing) {
print("Welcome to the java game of Rock Paper Scissors");
print("| ScoreBoard: your wins are = " + wins + "| your losses are = " + losses + "
| your ties are = " + ties + " |");
print("It is you vs the machine choose your weapon by its number");
print("0. Rock");
print("1. Paper");
print("2. Scissors");
user_choice = input.nextInt(); // Get user input from keyboard
machine_choice = myRand.nextInt(3); // Make a random number between 0 and 2 for the computer's choice.
// what each 'player' chose
print("Machine throws... " + machine_choice + " _-_ You picked... " + user_choice);
// results logic
if (user_choice == machine_choice) {
ties++;
print("It's a Tie Game!");
} else if ((user_choice == R && machine_choice == S) || (user_choice == S && machine_choice == P)
|| (user_choice == P && machine_choice == R)) {
wins++;
print("You the user Wins!");
} else {
losses++;
print("Sorry sport ... The Computer Wins!");
}
print("Want to continue playing ? ");
print("enter any positive number to keep going, or enter any negative number to stop");
int more = input.nextInt();
if (more < 0) {
print("ok now bye bye then ");
print("| ScoreBoard: your wins were = " + wins +
"| your losses were = " + losses + " | your ties were = " + ties + " |");
keep_playing = false;
}
}
}
}
</code>
</pre>
</figure>
</div>
<br />
<nav>
<h3>take me somewhere else</h3>
<a href="#TOP"> Top of page</a>| <a href="#TIP"> Tip Calculator</a>|
<a href="#PIG"> Pig Latin Translator</a> |
<a href="#RPS"> Rock Paper Scissors </a>|
<a href="#WTHR"> Weather Forecast</a> |
<a href="#DOG"> Random Dog Picture</a>
</nav>
<br />
<h2>
Now we can grow what we have coded above by adding two more playing
options for the cult-classic Rock Paper Scissors Lizard Spock (as seen on
'The Big Bang Theory').
</h2>
<h1 id="RPSLS">RPSLS</h1>
<hr />
<div class="interactive">
<h2>Select your weapon below & click the shoot button to play</h2>
<div class="options">
<div class="game" id="rock">
Rock<i class="far fa-hand-rock fa-3x"></i>
</div>
<div class="game" id="paper">
Paper<i class="far fa-hand-paper fa-3x"></i>
</div>
<div class="game" id="scissors">
Scissors<i class="far fa-hand-scissors fa-3x"></i>
</div>
<div class="game" id="lizard">
Lizard<i class="far fa-hand-lizard fa-3x"></i>
</div>
<div class="game" id="spock">
Spock<i class="far fa-hand-spock fa-3x"></i>
</div>
</div>
<div class="moves">
<h2>your move :</h2>
<div class="yourMove" id="you">choice</div>
<button class="rpsBtn" id="shoot">SHOOT</button>
<h2>computer throws :</h2>
<div class="compMove" id="comp">rock</div>
</div>
<div id="status">You Tie</div>
<div class="score">
<div id="win">0</div>
<div id="lose">0</div>
<div id="tie">0</div>
</div>
</div>
<a class="reset" href="https://brianlovega.github.io/talentPathCapstone/"
>Click here to reset the score board</a
>
<!-- yeah this is kinda cheating but it works -->
<hr />
<div class="rpsls">
<div class="jscode">
<figure>
<figcaption>JavaScript code used on this site here</figcaption>
<pre class="prettyprint">
<code>
/// click rock paper spock ect....
/// word under your move changes
/// color outline changes
/// red rock, silver scissors, white paper, blue spock, green lizard
/// press button for comps move
/// score and status updates
// start with your move
let you = document.getElementById("you");
let ym = null;
/// player choices of weapon
/// not a drop down menu - just click to pick - mobile friendly - no keyboard required
/// rock
let rock = document.getElementById("rock");
rock.addEventListener("click", rockPick);
function rockPick() {
you.innerText = "ROCK";
you.style.borderColor = "red";
ym = "rock";
}
/// paper
let paper = document.getElementById("paper");
paper.addEventListener("click", paperPick);
function paperPick() {
you.innerText = "PAPER";
you.style.borderColor = "white";
ym = "paper";
}
/// scissors
let scissors = document.getElementById("scissors");
scissors.addEventListener("click", sciPick);
function sciPick() {
you.innerText = "SCISSORS";
you.style.borderColor = "gray";
ym = "scissors";
}
/// lizard
let lizard = document.getElementById("lizard");
lizard.addEventListener("click", lizardPick);