# Functions - More Exercise

Jun 27th, 2019
170
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. 1. Carwash
2.
3. function carwash(input){
4.     let value=0;
5.     for (let comand of input){
6.
7.         switch(comand){
8. case "soap": value+=10; break;
9. case "water": value*=1.20; break;
10. case "vacuum cleaner": value*=1.25; break;
11. case "mud": value*=0.90; break;
12.         }
13.     }
14.
15.     console.log(`The car is \${value.toFixed(2)}% clean.`);
16. }
17.
18.
19. 2. Number modification
20.
21. function modifyNumber(input) {
22.     let sum = 0;
23.     let average=0;
24.     let length=0;
25.
26.    let numStr=String(input);
27.
28.    function findLength(numStr){
29.        length=numStr.length;
30.        return length;
31.    }
32.
33.  length=findLength(numStr);
34.
35.    function findSum(numStr,length){
36.    for (let i=0; i<length; i++){
37.        sum+=Number(numStr[i]);
38.    }
39.    return sum;
40. }
41. sum=findSum(numStr,length);
42.
43.
44. function append(numStr){
45.     numStr+="9";
46.     return numStr;
47. }
48.
49.
50. function findAverage(sum, length){
51.     average=sum/length;
52.     return average;
53. }
54.
55. average=findAverage(sum,length);
56.
57.    while(average<5){
58.        sum=0;
59.        numStr=append(numStr);
60.        length=findLength(numStr);
61.        sum=findSum(numStr,length);
62.        average=findAverage(sum,length);
63.
64.    }
65.
66.
67. console.log(numStr);
68. }
69.
70. 5. Print DNA
71.
72. function printDna(input){
73.     let line="";
74.     let dna=["A", "T", "C", "G", "T", "T", "A", "G", "G", "G"];
75.     let gene=0;
76.
77.     let linesPrinted=0;
78.
79.     while(linesPrinted<=input){
80.         let starsRep=2;
81.         let spaceRep=0;
82.
83.
84.
85.  for (let i=1; i<=3; i++){
86.      if (linesPrinted===input){
87.          break;
88.      }
89.      if (gene>9){
90.         gene=gene-10;
91.     }
92.     let nextGene=gene+1;
93. if (nextGene>9){
94.     nextGene=0;
95. }
96.      line="*".repeat(starsRep)+dna[gene]+"-".repeat(spaceRep)+dna[nextGene]+ "*".repeat(starsRep);
97.      console.log(line);
98.      linesPrinted++;
99.      spaceRep+=2;
100.      starsRep--;
101.      gene+=2;
102.
103.
104.
105.  }
106.
107.  if (linesPrinted===input){
108.     break;
109. }
110.
111. if (gene>9){
112.     gene=gene-10;
113. }
114. let nextGene=gene+1;
115. if (nextGene>9){
116.     nextGene=0;
117. }
118.  line="*"+dna[gene]+"--"+dna[nextGene]+"*";
119.  console.log(line);
120.  gene=nextGene+1;
121.  linesPrinted++;
122.
123.     }
124. }