Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save claudiainbytes/46f097d47367698e17bd98df5b0cc9cf to your computer and use it in GitHub Desktop.
Save claudiainbytes/46f097d47367698e17bd98df5b0cc9cf to your computer and use it in GitHub Desktop.
ES6 - Literal templates and tags
<html lang="es">
<head>
<meta charset="UTF-8">
<title>ES6</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
let u = 3;
let vu = 2800;
let moneda = "pesos";
function etiqueta(l, ...s){
var resultado = "";
var d = function(u, vu, moneda){
var arr = [];
switch(moneda){
case "dolares":
arr["simbolo"] = "USD $";
arr["cambio"] = vu * 1;
break;
case "pesos":
arr["simbolo"] = "COP $";
arr["cambio"] = vu * 2900;
break;
case "bolivares":
arr["simbolo"] = "VEF Bs. ";
arr["cambio"] = vu * 9.9951;
break;
}
return arr;
};
divisa = d(s[0],s[1],s[2]);
for( let i = 0; i < s.length; i++ ){
if( i == 1 ){
resultado += l[i] + divisa["simbolo"];
resultado += s[i] + divisa["cambio"];
}else{
resultado += l[i];
resultado += s[i];
}
}
return resultado;
}
let mensaje = etiqueta`Total de ${u} unidades es: ${u * vu} ${moneda}`;
document.write(mensaje);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment