Skip to content

cowsay CLI project with scaffolding #1

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

Merged
merged 1 commit into from
Oct 13, 2021
Merged
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
38 changes: 38 additions & 0 deletions challenge-cowsay-two/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Cowsay

Do you remember [Cowsay](https://github.com/CodeYourFuture/JavaScript-Core-1-Challenges)? We learned about node packages and made a cow say stuff. Now, we know more about programming, let's figure out how to make a cow say things in Node by ourselves.

## Project

For this project we don't need a package, a library or lots of options. Let's just get our own cow printing out and saying whatever we write in the command line. What would be helpful? I think we need to:

- [Accept an argument](https://nodejs.dev/learn/nodejs-accept-arguments-from-the-command-line) from the command line.
- Output to the command line. You've already done this with console.log.
- Make an ASCII cow.
- Write a function that puts the string into the cow's speech bubble.

Write your solution in the file solution1.js and test it by running your program in the command line. How will you handle it when no argument is given? How will you make the picture of a cow?

### Iterating

We could make our program more accessible by adding a command line interface that prompts us to write in the cow's words. What tools can we use? I think we could use:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you trying to nudge them towards removing the argument, or prompting if no argument was given? I feel like being slightly more explicit about that could be useful (this doesn't feel like super useful ambiguity to have them resolve :))


- A command line interface. I'll start you off by letting you know that there is a built in CLI called [readline](https://nodejs.dev/learn/accept-input-from-the-command-line-in-nodejs).
- Our ASCII cow again.
- And our cow function.

Write your solution in a file called solution2.js and test it by running your program in the command line. Use a prompt to ask for your cow saying.

Compare your approach to the sample solutions (you can unlock next week). Your solution might be different and that's ok. If you can print a cow and you can make it say different things, you solved it.

A slightly simpler ASCII cow that might help if you hit formatting issues.

```
/
/
^__^ /
(oo)'_______
(__) )-~
||----w |
|| ||
```
30 changes: 30 additions & 0 deletions challenge-cowsay-two/solution1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// =================
// Stripped down cowsayer CLI,
// no libraries
// https://nodejs.dev/learn/nodejs-accept-arguments-from-the-command-line
// =================

// 1. Accept arguments

// how will you accept arguments?

// 2. Make supplies for our speech bubble

let topLine = '_';
let bottomLine = '-';
let saying = '';

// 3. Make a cow that takes a string

function cowsay(saying) {
// how will you make the speech bubble contain the text?

// 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?
18 changes: 18 additions & 0 deletions challenge-cowsay-two/solution2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// =================
// Stripped down cowsayer CLI,
// no libraries or arguments
// https://nodejs.dev/learn/accept-input-from-the-command-line-in-nodejs
// =================

// 1. Make a command line interface.

// 2. Make supplies for our speech bubble

// 3. Make a cow that takes a string

const cow = (saying) => {
// how did you make the cow before?
}

// 4. Use readline to get a string from the terminal
// (with a prompt so it's clearer what we want)