Skip to content

Commit 2110d3f

Browse files
committed
cowsay CLI project with scaffolding
CodeYourFuture/syllabus#189
1 parent a0332a3 commit 2110d3f

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

challenge-cowsay-two/readme.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Cowsay
2+
3+
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.
4+
5+
## Project
6+
7+
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:
8+
9+
- [Accept an argument](https://nodejs.dev/learn/nodejs-accept-arguments-from-the-command-line) from the command line.
10+
- Output to the command line. You've already done this with console.log.
11+
- Make an ASCII cow.
12+
- Write a function that puts the string into the cow's speech bubble.
13+
14+
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?
15+
16+
### Iterating
17+
18+
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:
19+
20+
- 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).
21+
- Our ASCII cow again.
22+
- And our cow function.
23+
24+
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.
25+
26+
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.
27+
28+
A slightly simpler ASCII cow that might help if you hit formatting issues.
29+
30+
```
31+
/
32+
/
33+
^__^ /
34+
(oo)'_______
35+
(__) )-~
36+
||----w |
37+
|| ||
38+
```

challenge-cowsay-two/solution1.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// =================
2+
// Stripped down cowsayer CLI,
3+
// no libraries
4+
// https://nodejs.dev/learn/nodejs-accept-arguments-from-the-command-line
5+
// =================
6+
7+
// 1. Accept arguments
8+
9+
// how will you accept arguments?
10+
11+
// 2. Make supplies for our speech bubble
12+
13+
let topLine = '_';
14+
let bottomLine = '-';
15+
let saying = '';
16+
17+
// 3. Make a cow that takes a string
18+
19+
function cowsay(saying) {
20+
// how will you make the speech bubble contain the text?
21+
22+
// where will the cow picture go?
23+
24+
// how will you account for the parameter being empty?
25+
26+
}
27+
28+
//4. Pipe argument into cowsay function and return a cow
29+
30+
// how will you log this to the console?

challenge-cowsay-two/solution2.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// =================
2+
// Stripped down cowsayer CLI,
3+
// no libraries or arguments
4+
// https://nodejs.dev/learn/accept-input-from-the-command-line-in-nodejs
5+
// =================
6+
7+
// 1. Make a command line interface.
8+
9+
// 2. Make supplies for our speech bubble
10+
11+
// 3. Make a cow that takes a string
12+
13+
const cow = (saying) => {
14+
// how did you make the cow before?
15+
}
16+
17+
// 4. Use readline to get a string from the terminal
18+
// (with a prompt so it's clearer what we want)

0 commit comments

Comments
 (0)