This file contains 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
// Break ================================= | |
// Break ends a loop immediately | |
console.log('=== BREAK ==='); | |
for (let i = 0; i < 10; i++) { | |
console.log(i); | |
if (i === 5) { | |
break; | |
} |
This file contains 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 onlyVowels(str) { | |
let output = ''; | |
for (const char of str) { | |
const lowerCaseChar = char.toLowerCase(); | |
if ( | |
lowerCaseChar === 'a' || | |
lowerCaseChar === 'e' || | |
lowerCaseChar === 'o' || | |
lowerCaseChar === 'u' || |
This file contains 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 numberDoubler(num) { | |
let outputNum = num; | |
while (outputNum < 100) { | |
outputNum = outputNum * 2; | |
} | |
return outputNum; | |
} | |
function stringRepeater(str) { | |
let outputStr = str; |
This file contains 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 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; |
This file contains 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
// for (let i = 0; i < 20; i++) { | |
// console.log(i); | |
// } | |
// while (pinIsIncorrect) { | |
// askForPinCode(); | |
// } | |
// let i = 0; | |
// while (i < 20) { |
This file contains 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 disemvowel(str) { | |
let noVowelStr = ''; | |
for (const letter of str) { | |
// Determine whether each letter is a vowel | |
const lowerCaseLetter = letter.toLowerCase(); | |
const isVowel = ( | |
lowerCaseLetter === 'e' || |
This file contains 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 getSum(a, b) { | |
// Determine which number is smaller and bigger | |
let smallest = a; | |
let biggest = b; | |
if (b < a) { | |
smallest = b; | |
biggest = a; | |
} | |
This file contains 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 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]; |
This file contains 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
// ##### 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 ##### |
This file contains 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
/****************** | |
* YOUR CODE HERE * | |
******************/ | |
// addAll([1, 2, 3]) | |
function addAll(numbers) { | |
let sum = 0; | |
for (const number of numbers) { | |
sum = sum + number; |
NewerOlder