Skip to content

Instantly share code, notes, and snippets.

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") {
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...
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
function euclidGreatestCommonFactor(numOne, numTwo){
if (numOne > numTwo) {
var larger = numOne;
var smaller = numTwo;
}
else {
var larger = numTwo;
var smaller = numOne;
}
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) {
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)
}
}
function checkIfPowerOfTwo(num) {
while ((num % 2 === 0) && (num > 1)) {
num = num / 2
}
console.log(num === 1);
}
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);
}
}
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;
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"]],