diff --git a/challenges/challenge-cowsay-two/solution1.js b/challenges/challenge-cowsay-two/solution1.js index a7f2416b..8c8b0a78 100644 --- a/challenges/challenge-cowsay-two/solution1.js +++ b/challenges/challenge-cowsay-two/solution1.js @@ -5,22 +5,32 @@ // ================= // 1. Accept arguments - // how will you accept arguments? - +const argument = (process.argv[2]) ? process.argv.slice(2) : "" // 2. Make supplies for our speech bubble let topLine = '_'; let bottomLine = '-'; -let saying = ''; +let saying = `< ${argument.join(" ")}> `; // 3. Make a cow that takes a string function cowsay(saying) { // how will you make the speech bubble contain the text? - +console.log(` + ${topLine.repeat(saying.length)} + ${saying} + ${bottomLine.repeat(saying.length)} + / + / +^__^ / +(oo)'_______ +(__) )-~ + ||----w | + || ||`) // where will the cow picture go? + // how will you account for the parameter being empty? } @@ -28,3 +38,4 @@ function cowsay(saying) { //4. Pipe argument into cowsay function and return a cow // how will you log this to the console? +cowsay(saying) \ No newline at end of file diff --git a/challenges/challenge-cowsay-two/solution2.js b/challenges/challenge-cowsay-two/solution2.js index 8aca8572..fe53fd25 100644 --- a/challenges/challenge-cowsay-two/solution2.js +++ b/challenges/challenge-cowsay-two/solution2.js @@ -7,12 +7,37 @@ // 1. Make a command line interface. // 2. Make supplies for our speech bubble - +let topLine = '_'; +let bottomLine = '-'; // 3. Make a cow that takes a string const cow = (saying) => { // how did you make the cow before? + console.log(` + ${topLine.repeat(saying.length)} + ${saying} + ${bottomLine.repeat(saying.length)} + / + / + ^__^ / + (oo)'_______ + (__) )-~ + ||----w | + || ||`) } // 4. Use readline to get a string from the terminal -// (with a prompt so it's clearer what we want) \ No newline at end of file +// (with a prompt so it's clearer what we want) +const readline = require('node:readline'); + +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout, +}); + +rl.question(`Enter the phrase for the cow `, saying => { + + let formatted_saying = `< ${saying}> `; + cow(formatted_saying) + rl.close(); +});