-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjstasks.js
More file actions
42 lines (35 loc) · 1.1 KB
/
Copy pathjstasks.js
File metadata and controls
42 lines (35 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Task 1 Build a function that does currency converter from USD to UAH (1 USD = 8 UAH).
function convert (amount){
const RATE= 8;
return amount*Rate;
}
//Task 2 A function which returns reversed string.
function reverse(str){
const splitStr= str.split('');
const reverseStr= splitStr.reverse();
const jointStr= reverseStr.join('');
return jointStr;
}
//Task 3 A function which prints the stair picture of size n
function printStairs(n){
let str= '';
for (let i= 0;i<n;i++){
console.log(str+='#');
}
}
//Task 4 A function which returns total sum of a range
function startRange (start,end){
let sum = 0;
for (let i=start;i<=end;i++){
sum = sum + i;
}
return sum;
}
//Task 5 Write a function which returns the smallest of three numbers.
function min(a,b,c){
return (a<=b ? a:b),(b<=c ? b:c),(c<=b ? c:b);
}
//Task 7 A function which transforms first and last letter to uppercase (use built in string’s method).
function firstAndLastToUpper(str){
return str[0].toUpperCase() + str.slice(1,str.length-1) + str[str.length-1].toUpperCase();
}