CCCPaste

Functions - More Exercise

1. Carwash

function carwash(input){
    let value=0;
    for (let comand of input){

        switch(comand){
case "soap": value+=10; break;
case "water": value*=1.20; break;
case "vacuum cleaner": value*=1.25; break;
case "mud": value*=0.90; break;
        }
    }

    console.log(`The car is ${value.toFixed(2)}% clean.`);
}


2. Number modification

function modifyNumber(input) {
    let sum = 0;
    let average=0;
    let length=0;

   let numStr=String(input);

   function findLength(numStr){
       length=numStr.length;
       return length;
   }
 
 length=findLength(numStr);

   function findSum(numStr,length){
   for (let i=0; i9){
        gene=gene-10;
    }
    let nextGene=gene+1;
if (nextGene>9){
    nextGene=0;
}
     line="*".repeat(starsRep)+dna[gene]+"-".repeat(spaceRep)+dna[nextGene]+ "*".repeat(starsRep);
     console.log(line);
     linesPrinted++;
     spaceRep+=2;
     starsRep--;
     gene+=2;
     

 
 }

 if (linesPrinted===input){
    break;
}

if (gene>9){
    gene=gene-10;
}
let nextGene=gene+1;
if (nextGene>9){
    nextGene=0;
}
 line="*"+dna[gene]+"--"+dna[nextGene]+"*";
 console.log(line);
 gene=nextGene+1;
 linesPrinted++;

    }
}