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 files via upload #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
95 changes: 90 additions & 5 deletions exercises.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
//Do not change any of the function names

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

function greeting(language) {
if (language === 'German'){
return 'Guten Tag!';
} else if (language === 'English'){
return 'Hello!';
} else if (language === 'Spanish'){
return 'Hola!';
} else {
return 'Hello!';
}
//return a greeting for three different languages:
//language: 'German' -> 'Guten Tag!'
//language: 'English' -> 'Hello!'
Expand All @@ -14,15 +29,30 @@ function greeting(language) {
}

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

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

function isInteger(num) {
if(num % 1 === 0) {
return true;
} else{
return false;
}
//return true if num is an integer
//0.8 -> false
//1 -> true
Expand All @@ -32,72 +62,127 @@ function isInteger(num) {
}

function fizzBuzz(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;
}
//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
}

//I'm not working
function isPrime(num) {
for(var i = 0; i < 5; i++){
while (i < 2){
i++;
}
if (num === 0 || num === 1){
return false;
}
else if (num % i != 0){
return true;
}else {
return false;
}
//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
}
}

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

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

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

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

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

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

//im not working
function wordsToSentence(words) {
return words.join(' ');
//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!'
}

//I'm not working
function contains(arr, item) {
if (arr.indexOf(item) != -1) {
return true;
} else {
return false;
}
//check to see if item is inside of arr
//return true if it is, otherwise return false
}

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

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

function largestNumber(numbers) {
var max = Math.max.apply(null, numbers);
return max;
//numbers is an array of integers
//return the largest integer
}
Expand Down