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

Add my solution to exercises.js and README.md #8

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
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@
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 loop
A structure that repeats a block of statements a certain amount of times. It has a counter variable, a test condition, and it increases or decreases the counter variable every time it loops.
The for loop repeats the block of statements as long as the test condition is true. It checks the test condition each time it wants to loop, and if the condition evaluates to true, the for loop
executes the block of statements, increases or decreases the counter variable, and then rechecks the test condition.
* && || !
&& is logical AND. It returns true when both expressions or statements on each side of it evaulte to true, otherwise it returns false.
|| is logical OR. It returns true whenever at least one of the expression or statements is true.
* Array
An array is a list of elements. An array is zero based. So to access it's first element you must use 0 as the index, to access it's second element use the index 1, and so on.
* git
Git is a version control system. It allows a group of people to work on the same code at the same time without creating conflicts from their changes that would happen in a normal workflow.
* GitHub
Github is the online code storage area that git uses for its version control.


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

Done

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

Expand Down
111 changes: 93 additions & 18 deletions exercises.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,39 @@

function getBiggest(x, y) {
//x and y are integers. Return the larger integer
//if they are the same return either one
//if they are the same return either one
return (x > y) ? x : y;
}

function greeting(language) {
//return a greeting for three different languages:
//language: 'German' -> 'Guten Tag!'
//language: 'English' -> 'Hello!'
//language: 'Spanish' -> 'Hola!'
//if language is undefined return 'Hello!'
//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
//otherwise return false
return (num == 10 || num == 5) ? true : false;
}

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

function isInteger(num) {
Expand All @@ -28,78 +43,138 @@ function isInteger(num) {
//1 -> true
//-10 -> true
//otherwise return false
//hint: you can solve this using Math.floor
//hint: you can solve this using Math.floor
return (num === Math.floor(num)) ? true : 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
//otherwise return num
if (num % 3 == 0 && num % 5 == 0) {
return ('fizzbuzz');
}
else if (num % 5 == 0) {
return ('buzz');
}
else if (num % 3 == 0) {
return ('fizz');
}
else {
return num;
}
}

function isPrime(num) {
//return true if num is prime.
//otherwise return false
//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
//note: 0 and 1 are NOT considered prime numbers
if (num==0 || num==1) {
return false;
} //end if
else {
for(var i=2; i<num;i++) {
if(num%i==0){
return false;
} //end if
} //end for
} //end else
return true;
}

function returnFirst(arr) {
//return the first item from the array
//return the first item from the array
return arr.shift();
}

function returnLast(arr) {
//return the last item of the array
//return the last item of the array
return arr.pop();
}

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

function incrementByOne(arr) {
//arr is an array of integers
//increase each integer by one
//return the array
//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
//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
//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!'
//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
//return true if it is, otherwise return false
for (var i = 0; i < arr.length; i++) {
if (arr[i] === item) {
return true;
}
} //end for
return false;
}

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

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

function largestNumber(numbers) {
//numbers is an array of integers
//return the largest integer
//return the largest integer
//null points to no object - so largest will have 'no value'
var largest = null;
for (var i = 0; i < numbers.length; i++) {
if (numbers[i]>largest){
largest = numbers[i];
}
} //end for
return largest;
}

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