From 2c5e98159286a7cfcab55b35ef3c44b410393796 Mon Sep 17 00:00:00 2001 From: Matthew Huntington Date: Wed, 19 Apr 2023 17:10:14 -0400 Subject: [PATCH] putting it all together --- random.js | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/random.js b/random.js index ee2b53a..e6d07f1 100644 --- a/random.js +++ b/random.js @@ -1,15 +1,15 @@ -//const numBeats = Math.ceil(Math.random()*9); +const numBeats = Math.ceil(Math.random()*9); -//let resultString = ''; -//const instructionPosibilities = [ 'n', 'p', 'm', 'b' ] +let resultString = ''; +const instructionPosibilities = [ 'n', 'p', 'm', 'b' ] -//for(let i = 1; i <= numBeats; i++){ - //const instructionIndex = Math.floor(Math.random()*instructionPosibilities.length); +for(let i = 1; i <= numBeats; i++){ + const instructionIndex = Math.floor(Math.random()*instructionPosibilities.length); - //resultString += instructionPosibilities[instructionIndex] + ' '; -//} + resultString += instructionPosibilities[instructionIndex] + ' '; +} -//console.log(resultString); +console.log(resultString); const breakDown = (node)=>{ @@ -32,7 +32,7 @@ const breakDown = (node)=>{ return node; } -const tree = breakDown({value:10}); +const tree = breakDown({value:numBeats}); //console.dir(tree, {depth:null}); @@ -102,6 +102,14 @@ const getLeaves = (node)=>{ } } } -const leaves = getLeaves(tree); - -console.dir(leaves, {depth:null}); +const claves = getLeaves(tree); +if(Number.isInteger(claves)){ + console.log(claves); +} else { + if(Number.isInteger(claves[0])){ + console.log(claves); + } else { + const clave = claves[Math.floor(Math.random()*claves.length)]; + console.log(clave); + } +}