This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function inconsistentAdder(numOne, numTwo) { | |
| console.log("Let's play a game! Me, the program, will flip a coin."); | |
| console.log("If it's heads, I'll add up your numbers,"); | |
| console.log("and if it's tails, I'll throw them back in your face."); | |
| console.log("Flipping a coin..."); | |
| var add = function add(numOne, numTwo) { return numOne + numTwo}; | |
| var coin = ["heads", "tails"][Math.floor(Math.random())]; | |
| if (coin === "heads") { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Let's play a game! Me, the program, will flip a coin. | |
| If it's heads, I'll add up your numbers, | |
| and if tails, I'll throw them back in your face. | |
| Flipping a coin... | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def inconsistent_adder(num1, num2) | |
| puts "Let's play a game! Me, the program, will flip a coin." | |
| puts "If it's heads, I'll add up your numbers," | |
| puts "and if tails, I'll throw them back in your face." | |
| puts "Flipping a coin..." | |
| sleep(4) | |
| add = lambda {|x, y| x + y} | |
| coin = ["heads", "tails"].sample | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function euclidGreatestCommonFactor(numOne, numTwo){ | |
| if (numOne > numTwo) { | |
| var larger = numOne; | |
| var smaller = numTwo; | |
| } | |
| else { | |
| var larger = numTwo; | |
| var smaller = numOne; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function primeTester(num) { | |
| var range = new Array; | |
| for (var i=1; i <= num; i++) { | |
| range.push(i); | |
| } | |
| var factors = new Array; | |
| for (var i=0; i < range.length; i++) { | |
| var current = range[i]; | |
| if (num % current === 0) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function temperatureConversion(temp, toNewType) { | |
| if ((toNewType[0] === "c") || (toNewType[0] === "C")) { | |
| // convert to celsius | |
| console.log((temp - 32) * (5/9)) | |
| } | |
| else { | |
| // convert to fahrenheit | |
| console.log((temp * 9/5) + 32) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function checkIfPowerOfTwo(num) { | |
| while ((num % 2 === 0) && (num > 1)) { | |
| num = num / 2 | |
| } | |
| console.log(num === 1); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function findPerfectSquares(array) { | |
| var squares = new Array; | |
| for (var i=0; i < array.length; i++) { | |
| var num = array[i]; | |
| var numFactors = new Array; | |
| for (var j=2; j < num; j++) { | |
| if (num % j === 0) { | |
| numFactors.push(j); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function bubbleSort(array) { | |
| var sorted = false; | |
| while (!sorted) { | |
| for (var i=0; i < array.length - 1; i++) { | |
| var a = array[i]; | |
| var b = array[i + 1]; | |
| if (a > b) { | |
| array[i] = b; | |
| array[i + 1] = a; | |
| break; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function rockPaperScissors(string) { | |
| var options = { | |
| 1: "Rock", | |
| 2: "Paper", | |
| 3: "Scissors", | |
| }; | |
| var judge = { | |
| "Function wins!": [["Rock", "Paper"], ["Paper", "Scissors"], ["Scissors", "Rock"]], | |
| "You win!": [["Paper", "Rock"], ["Scissors", "Papers"], ["Rock", "Scissors"]], |