Skip to content
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
27 changes: 27 additions & 0 deletions arraySolution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*Write a function that accepts an array of 10 integers (between 0 and 9), that returns a string of those numbers in the form of a phone number.

Example
createPhoneNumber([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) // => returns "(123) 456-7890"
The returned format must be correct in order to complete this challenge.

Don't forget the space after the closing parentheses!


const chai = require("chai");
const assert = chai.assert;
chai.config.truncateThreshold=0;

describe("Create Phone Number", () => {
it("Fixed tests", () => {
assert.strictEqual(createPhoneNumber([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]), "(123) 456-7890");
assert.strictEqual(createPhoneNumber([1, 1, 1, 1, 1, 1, 1, 1, 1, 1]), "(111) 111-1111");
assert.strictEqual(createPhoneNumber([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]), "(123) 456-7890");
});
}); */


function createPhoneNumber(numbers){

return `(${numbers[0]}${numbers[1]}${numbers[2]}) ${numbers[3]}${numbers[4]}${numbers[5]}-${numbers[6]}${numbers[7]}${numbers[8]}${numbers[9]}`
}

19 changes: 19 additions & 0 deletions booleanArraySolution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*Consider an array/list of sheep where some sheep may be missing from their place. We need a function that counts the number of sheep present in the array (true means present).

For example,

[true, true, true, false,
true, true, true, true ,
true, false, true, false,
true, false, false, true ,
true, true, true, true ,
false, false, true, true]
The correct answer would be 17.

Hint: Don't forget to check for bad values like null/undefined*/

function countSheeps(arrayOfSheep) {
const present = arrayOfSheep.filter(sheep => sheep);
return present.length;
}

28 changes: 28 additions & 0 deletions whileLoopSolution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//loop solution for Task
/*Complete function padIt, which accepts 2 parameters:

str: a string representing the string to pad. We will pad it with "*" symbols on its left side and on its right side.
n: a number indicating how many times to pad the string.
Behaviour
You need to write a loop statement within the function that loops n times. Each time through the loop it will add one * to str, alternating on which side it is padded: the first time will add a * to the left side of str, the second time will add a * to the right side, and so on.

Finally, return the padded string.*/



function padIt(str,n){
//declaring function passing in parameters
while(n>0){
//while statement that "while" variable "n" is more than 0 function will run//
if(n%2 === 0) {
str = str + "*";
//if "n" is divisible by 2 and equals 0 string gets a "*" added to the right
}else{
str = "*" + str;
}//else string add to left
n --;
//confused about this one
}
return str;
//return string to orginal postion (able to be ran again)
}