From f7faf753e9df20b917ff16bf94565976830c7d06 Mon Sep 17 00:00:00 2001 From: jotero Date: Thu, 3 Dec 2020 09:18:53 -0300 Subject: [PATCH] =?UTF-8?q?resoluci=C3=B3n=20juego=20de=20dardos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- juegoDardos.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 juegoDardos.js diff --git a/juegoDardos.js b/juegoDardos.js new file mode 100644 index 0000000..fe76e8f --- /dev/null +++ b/juegoDardos.js @@ -0,0 +1,28 @@ +function partida_dardos(radios) { + let total = 0, + todosMenores = true, + tieneValores = false; + radios.forEach((tiro) => { + tieneValores = true; + if (tiro > 10) { + todosMenores = false; + } else { + if (tiro >= 5 && tiro <= 10) { + total = total + 5; + todosMenores = false; + } else { + total = total + 10; + } + } + }); + if (todosMenores && tieneValores) { + total = total + 100; + } + return total; +} + +//prueba tiros +console.log(partida_dardos([1, 5, 11])); +console.log(partida_dardos([15, 20, 30])); +console.log(partida_dardos([1, 2, 3, 4])); +console.log(partida_dardos([]));