Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS Lesson 2 Work #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
## Instructions
---
1. Feynman Writing Prompts - Write out explanations of the following concepts like you are explaining it to a 12 year old. Doing this will help you quickly discover any holes in your understanding. Ask your questions on Slack.
* `for`
* `&&`, `||`, `!`
* Arrays
* Git
* GitHub

* `for` = We use for loops to repeat an action a certain amount of times.
* `&&`, `||`, `!` = && is the and operator and is used to check if two conditions are evaluated to true. Both conditions must be true when using the && operator for it to execute. || is the or operator and is used to check if either of the conditions are true. One condition can be true and one false and it will still return true when using the or operator. ! is used for indicating that something is the opposite. So !true would be false and !false would be true.
* Arrays = Arrays are lists that can be stored to a single variable using multiple strings instead of assigning only one string to a variable.
* Git = A version control system to keep track of changes in our files and also making collaborating work with other people easier.
* GitHub = A website used to store code files. It's the "HUB" for Git.


2. Install git. https://git-scm.com/downloads


3. Fork and clone this repo. When you need to commit use the following commands.

* `git status`
* `git add --all`
* `git status`
Expand Down
82 changes: 81 additions & 1 deletion exercises.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
function getBiggest(x, y) {
// x and y are integers. Return the larger integer
// if they are the same return either one
if (x > y) {
return x;
} else if (y > x) {
return y;
} else {
return x || y;
}
}

function greeting(language) {
Expand All @@ -11,15 +18,34 @@ function greeting(language) {
// language: 'English' -> 'Hello!'
// language: 'Spanish' -> 'Hola!'
// if language is undefined return 'Hello!'
if (language === 'German') {
return 'Guten Tag!';
} else if (language === 'English') {
return 'Hello!';
} else if (language === 'Spanish') {
return 'Hola!';
} else {
return 'Hello!';
}
}

function isTenOrFive(num) {
// return true if num is 10 or 5
// otherwise return false
if (num === 10 || num === 5) {
return true;
} else {
return false;
}
}

function isInRange(num) {
// return true if num is less than 50 and greater than 20
if (num < 50 && num > 20) {
return true;
} else {
return false;
}
}

function isInteger(num) {
Expand All @@ -29,13 +55,27 @@ function isInteger(num) {
// -10 -> true
// otherwise return false
// hint: you can solve this using Math.floor
if (Number.isInteger(num)) {
return true;
} else {
return false;
}
}

function fizzBuzz(num) {
// if num is divisible by 3 return 'fizz'
// if num is divisible by 5 return 'buzz'
// if num is divisible by 3 & 5 return 'fizzbuzz'
// otherwise return num
if (num % 3 === 0 && num % 5 === 0) {
return 'fizzbuzz';
} else if (num % 3 === 0) {
return 'fizz';
} else if (num % 5 === 0) {
return 'buzz';
} else {
return num;
}
}

function isPrime(num) {
Expand All @@ -44,62 +84,102 @@ function isPrime(num) {
// hint: a prime number is only evenly divisible by itself and 1
// hint2: you can solve this using a for loop
// note: 0 and 1 are NOT considered prime numbers
for (var i = 2; i <= num - 1; i++) {
if (num % i === 0) {
return false;
}
}
return num > 1;
}

function returnFirst(arr) {
// return the first item from the array
return arr[0];
}

function returnLast(arr) {
// return the last item of the array
return arr[arr.length - 1];
}

function getArrayLength(arr) {
// return the length of the array
return arr.length;
}

function incrementByOne(arr) {
// arr is an array of integers
// arr is an array of integers
// increase each integer by one
// return the array
for (var i = 0; i < arr.length; i++) {
arr[i] += 1;
}
return arr;
}

function addItemToArray(arr, item) {
// add the item to the end of the array
// return the array
arr.push(item);
return arr;
}

function addItemToFront(arr, item) {
// add the item to the front of the array
// return the array
// hint: use the array method .unshift
arr.unshift(item);
return arr;
}

function wordsToSentence(words) {
// words is an array of strings
// return a string that is all of the words concatenated together
// spaces need to be between each word
// example: ['Hello', 'world!'] -> 'Hello world!'
return words.join(' ');
}

function contains(arr, item) {
// check to see if item is inside of arr
// return true if it is, otherwise return false
if (arr.includes(item)) {
return true;
} else {
return false;
}
}

function addNumbers(numbers) {
// numbers is an array of integers.
// add all of the integers and return the value
var allNumbers = 0;
for (var i = 0; i < numbers.length; i++) {
allNumbers += numbers[i];
}
return allNumbers;
}

function averageTestScore(testScores) {
// testScores is an array. Iterate over testScores and compute the average.
// return the average
var allScores = 0;
for (var i = 0; i < testScores.length; i++) {
allScores += testScores[i];
}
return allScores / testScores.length;
}

function largestNumber(numbers) {
// numbers is an array of integers
// return the largest integer
var largest = numbers[0];
for (var i = 0; i < numbers.length; i++) {
if (largest <= numbers[i]) {
largest = numbers[i];
}
}
return largest;
}

// Do not modify code below this line.
Expand Down