Skip to content

LONDON-JAN-25 | ANDREI FILIPPOV | Module-Data Flows | WEEK 3 Cowsay #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions challenges/challenge-cowsay-two/solution1.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,37 @@
// =================

// 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?

}

//4. Pipe argument into cowsay function and return a cow

// how will you log this to the console?
cowsay(saying)
29 changes: 27 additions & 2 deletions challenges/challenge-cowsay-two/solution2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
// (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();
});