Skip to content

Instantly share code, notes, and snippets.

// Break =================================
// Break ends a loop immediately
console.log('=== BREAK ===');
for (let i = 0; i < 10; i++) {
console.log(i);
if (i === 5) {
break;
}
function onlyVowels(str) {
let output = '';
for (const char of str) {
const lowerCaseChar = char.toLowerCase();
if (
lowerCaseChar === 'a' ||
lowerCaseChar === 'e' ||
lowerCaseChar === 'o' ||
lowerCaseChar === 'u' ||
function numberDoubler(num) {
let outputNum = num;
while (outputNum < 100) {
outputNum = outputNum * 2;
}
return outputNum;
}
function stringRepeater(str) {
let outputStr = str;
function foldTo(distance) {
// If we're given a bogus distance, return null
if (distance < 0) {
return null;
}
// Initial paper thickness and number of folds
let paperThickness = 0.0001;
let numFolds = 0;
// for (let i = 0; i < 20; i++) {
// console.log(i);
// }
// while (pinIsIncorrect) {
// askForPinCode();
// }
// let i = 0;
// while (i < 20) {
function disemvowel(str) {
let noVowelStr = '';
for (const letter of str) {
// Determine whether each letter is a vowel
const lowerCaseLetter = letter.toLowerCase();
const isVowel = (
lowerCaseLetter === 'e' ||
function getSum(a, b) {
// Determine which number is smaller and bigger
let smallest = a;
let biggest = b;
if (b < a) {
smallest = b;
biggest = a;
}
function maxDiff(list) {
// If we get an empty list, just return 0
if (list.length === 0) {
return 0;
}
// Initialize biggest and smallest nums to the first item in the list
let biggestNum = list[0];
let smallestNum = list[0];
// ##### Introduction #####
//
// The below assignment will require NO functions
//
// Instead, our focus is going to be on console.logging the characters at certain indices of strings.
//
// ##### Challenges #####
/******************
* YOUR CODE HERE *
******************/
// addAll([1, 2, 3])
function addAll(numbers) {
let sum = 0;
for (const number of numbers) {
sum = sum + number;