Skip to content

Commit ec6b5fa

Browse files
committed
updated
1 parent 38a71d9 commit ec6b5fa

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

JavaScript Problem Solving/veryEasy.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,78 @@ function isLastCharacterN(word) {
2626
return false;
2727
}
2828
}
29+
30+
31+
/*
32+
Check String for Spaces
33+
Create a function that returns true if a string contains any spaces.
34+
////////////////////////////////////////////////////////////////////
35+
*/
36+
function hasSpaces(str) {
37+
if (str.includes(" ")) {
38+
return true;
39+
} else {
40+
return false;
41+
}
42+
}
43+
44+
45+
/*
46+
Multiply Every Array Item by Two
47+
Create a function that takes an array with numbers and return an array with the elements multiplied by two.
48+
////////////////////////////////////////////////////////////////////
49+
*/
50+
function getMultipliedArr(arr) {
51+
let multi = arr.map(function(num) {
52+
return num * 2;
53+
});
54+
return multi;
55+
}
56+
57+
58+
/*
59+
Extract City Facts
60+
Create a function that takes an object as an argument and returns a string with facts about the city. The city facts will need to be extracted from the object's three properties:
61+
name, population, continent
62+
The string should have the following format: X has a population of Y and is situated in Z (where X is the city name, Y is the population and Z is the continent the city is situated in).
63+
////////////////////////////////////////////////////////////////////
64+
*/
65+
function cityFacts(city) {
66+
let getCity = city.name;
67+
let getPopulation = city.population;
68+
let getContinent = city.continent;
69+
return `${getCity} has a population of ${getPopulation} and is situated in ${getContinent}`;
70+
}
71+
72+
73+
/*
74+
Add a Consecutive List of Numbers
75+
Write a function that takes the last number of a consecutive list of numbers and returns the total of all numbers up to and including it.
76+
////////////////////////////////////////////////////////////////////
77+
*/
78+
function addUpTo(n) {
79+
return n * (n + 1) / 2;
80+
}
81+
82+
83+
/*
84+
Shapes With N Sides
85+
Create a function that takes a whole number as input and returns the shape with that number's amount of sides. Here are the expected outputs to get from these inputs.
86+
Note: I initially did a large if/else array but this seems a lot better.
87+
////////////////////////////////////////////////////////////////////
88+
*/
89+
function nSidedShape(n) {
90+
let shapes = {
91+
1: "circle",
92+
2: "semi-circle",
93+
3: "triangle",
94+
4: "square",
95+
5: "pentagon",
96+
6: "hexagon",
97+
7: "heptagon",
98+
8: "octagon",
99+
9: "nonagon",
100+
10: "decagon",
101+
}
102+
return shapes[n];
103+
}

0 commit comments

Comments
 (0)