convert dollar JS [closed]

0

module.exports = function coinConvert(usDollars) {
  var arr = [];
  var peruvianSoles /* tu código aquí */;
  var mexicanPesos /* tu código aquí */;
  var chileanPesos /* tu código aquí */;

  // Añade el monto equivalente en soles
  arr.push(/* tu código aquí */);

  // Añade el monto equivalente en pesos mexicanos
  arr.push(/* tu código aquí */);

  // Añade el monto equivalente en pesos chilenos
  arr.push(/* tu código aquí */);

  return arr;
};
  

Can you help me with this, please? It is a very simple exercise   Javascript.

DATA:

soles = dollars * 3.25

pesosMexicanos = dollars * 18

pesosChilenos = dollars * 660

EXAMPLE:

function coinConvert(dollar = 50) {
  soles = dollar * 3.25;    
  pesosMexicanos = dollar * 18;    
  pesosChilenos = dollar * 660;    
  console.log(soles, pesosMexicanos, pesosChilenos); 
  // --> [162.5, 900, 33000]
}
    
asked by Valeria Cossio 15.03.2018 в 07:59
source

1 answer

1

As I put in the comment, you can pass to the function the parameters of the currency you want to convert and the amount. And then depending on the currency then give the value to multiplication. Finally make a return of that result.

This way you can call the function for any of the coins or with any amount as many times as you want.

You can do a console log like what I did, or save a result in a variable and then treat it for example.

console.log(coinConvert("Soles",10));

function coinConvert(moneda,cantidad) {
  switch(moneda){
    case "Soles":
      moneda=3.25;
      break;
    case "Pesos Mexicanos":
      moneda=18;
      break;
    case "Pesos Chilenos ":
      moneda=660;
      break;
  }
  
  var resultado = moneda * cantidad;
  return resultado;
}
    
answered by 15.03.2018 / 10:40
source