*** shmohamud has quit (Remote host closed the connection) | 00:55 | |
*** shmohamud has quit (Ping timeout: 480 seconds) | 01:07 | |
*** shmohamud has quit (Ping timeout: 480 seconds) | 01:43 | |
*** shmohamud has quit (Remote host closed the connection) | 02:33 | |
*** shmohamud has quit (Ping timeout: 480 seconds) | 02:48 | |
*** shmohamud has quit (Ping timeout: 480 seconds) | 09:42 | |
*** fkoikoi has quit (Quit: Leaving) | 10:12 | |
*** tboimah has quit (Ping timeout: 480 seconds) | 10:26 | |
*** dcammue has quit (Ping timeout: 480 seconds) | 12:36 | |
*** tboimah_ has quit (Read error: Connection reset by peer) | 12:42 | |
*** tboimah_ has quit (Ping timeout: 480 seconds) | 13:01 | |
ubuntourist | hi tboimah | 13:04 |
---|---|---|
tboimah | Good morning ubuntourist | 13:04 |
ubuntourist | I'll launch right in today... Have you been folowing the log? | 13:05 |
tboimah | mulbah said that he will not be here today, because he have something to take care of. | 13:05 |
tboimah | not really because my computer screem was given problem, i thought i email on that | 13:06 |
tboimah | *you | 13:06 |
ubuntourist | You did. But I thought you said that you had two problems: One was your computer screen and the problem | 13:07 |
tboimah | and i just arriving at the mcss office to turing online today but i will read it after the class today | 13:07 |
ubuntourist | was that you could not get to the school. I just thought that maybe you had succeeded in going to the school eventually. | 13:07 |
ubuntourist | Anyway, mulbah and I got stuck: I am trying to get back to the iidea of fields and field delimiters. | 13:07 |
ubuntourist | Field delimiters are sometimes also called field dividers or field separators. | 13:08 |
ubuntourist | Several weeks ago we talked about fields and field delimiters when we way back when we were discussing | 13:09 |
ubuntourist | file ownership and file permissions. We looked at /etc/passwd and /etc/group and talked about how the data | 13:10 |
ubuntourist | in those files was organized into fields. | 13:10 |
ubuntourist | This is why I want you both to take good notes: When I asked him how to split a line like | 13:11 |
ubuntourist | song_of_joy.ly: composer = "Unknown" | 13:12 |
ubuntourist | into two fields, with the first field being the file name, he did not seem to know what field or field delimiter meant. | 13:13 |
tboimah | A delimited field is a variable-length field where the field length is set based on the field's contents. | 13:14 |
ubuntourist | But previously, you both said you understood fields and field delimiters when we used "cut" with /etc/passwd. | 13:14 |
ubuntourist | (I mean you understood after I explained it several sessions ago.) | 13:15 |
ubuntourist | So. The question is: Do you remember how to use cut? And what is meant by field and field delimiter? | 13:16 |
tboimah | like i said A delimited field or field delimited is a variable-length field where the field length is set based on the field's contents. | 13:16 |
ubuntourist | OK. So, in a line like: | 13:17 |
ubuntourist | song_of_joy.ly: composer = "Unknown" | 13:17 |
ubuntourist | what is the delimiter that would split the line where I want it to split? You've quoted a definition but does it mean anything to you? | 13:18 |
tboimah | the delimiter will be colon ":" in the sentence you just wrote | 13:19 |
ubuntourist | Excellent. Maybe you can explain it to mulbah better than I can. | 13:20 |
ubuntourist | I don't want to give him the answers. I want him to come to the understanding of what a field is and what a delimiter is. | 13:20 |
ubuntourist | Anyway... The reason we're going back to that: We're finishing up that README and script movie I sent several weeks ago. | 13:21 |
ubuntourist | I'm going to repeat myself a bit, because a lot of this is in the log from when you were unable to come. So, I'll be brief, and you can | 13:22 |
ubuntourist | either ask questions or go back and read the IRC logs that you've missed. Maybe both. | 13:22 |
tboimah | okay | 13:23 |
ubuntourist | So..... You might remember: We were filtering a list of files. | 13:23 |
tboimah | yeah dose file the end with extension ".ly" | 13:23 |
ubuntourist | "locate ly" to find all files with "ly" in the file name (inculding names we don't want like "plymouth") | 13:24 |
tboimah | sure | 13:24 |
ubuntourist | "grep "\.ly$" to filter for only the ones that END with ".ly", "grep kjcole" to find only the ones I own, etc. etc. | 13:25 |
ubuntourist | Now, the fun part: | 13:25 |
tboimah | let rod | 13:25 |
ubuntourist | You remember we did "for filename in *" and then used $filename as the variable. | 13:25 |
tboimah | yeah, that's the for loop | 13:26 |
ubuntourist | the "*" was an iterator -- it created a list of file names that we could pluck one at a time. | 13:26 |
ubuntourist | Here's the important part: We can do the same thing with the big filter we created. | 13:27 |
tboimah | that is the same name for it in python "*" | 13:27 |
tboimah | okay | 13:27 |
ubuntourist | Instead of using the * wildcard for "all files in this directory" | 13:27 |
ubuntourist | we can take any command -- or group of commands -- that produces output and use those instead of the wildcard. | 13:28 |
tboimah | sound intresting | 13:29 |
ubuntourist | If you take something like "locate ... | grep ... | grep ... | egrep ..." and surround it with "$(" and ")" | 13:29 |
ubuntourist | you can substitute it for the wildcard. | 13:29 |
ubuntourist | for filename in $( locate ly | grep "\.ly$" | grep kjcole | egrep -v "(frayedknot|_lilypond|...)") | 13:30 |
ubuntourist | The part $( locate ly | grep "\.ly$" | grep kjcole | egrep -v "(frayedknot|_lilypond|...)") is just | 13:31 |
ubuntourist | the filter we created, enclosed inside $( ... ) | 13:31 |
ubuntourist | Time to tmate | 13:32 |
ubuntourist | ssh NVGxDJURakBprzarF4RHxEACB@lon1.tmate.io | 13:32 |
ubuntourist | I think I mentioned, in Bash, when you have a very long line, you can break it up for easier reading | 13:35 |
ubuntourist | by adding a backslash \ to the end. So that first line is really | 13:35 |
tboimah | one line | 13:35 |
ubuntourist | for filename in $(locate ly | grep ... | grep ... | egrep ...) | 13:35 |
ubuntourist | The egrep here is eliminating directories that I don't want. The regular expression pattern | 13:37 |
ubuntourist | (xxxxx|yyyyy|zzzz) -- where you have several values inside parenthesis and separated by the | means | 13:38 |
ubuntourist | match xxxxx OR yyyyy OR zzzz | 13:38 |
ubuntourist | and the "-v" means DON'T. | 13:38 |
ubuntourist | So egrep -v "(/\.|FrayedKnotArts|...)" means | 13:39 |
ubuntourist | eliminate (don't match) files that have "/." or FrayedKnotArts or engraving or rosegarden or ... | 13:40 |
ubuntourist | anywhere in the full file path. So if there was a /home/kjcole/bla-bla-blah/FrayedKnotsArt/composition.ly it would be eliminated | 13:41 |
ubuntourist | from the list. (It ends in ".ly" and is in a "kjcole" directory, but it also has FrayedKnotArts. So it gets kicked out.) | 13:42 |
ubuntourist | OK. So now we've got this list and we're using it as an iterator. | 13:42 |
ubuntourist | The egrep after the "do" has a "-H". Let's explore the -H for a mintue. I think the history command will let me repeat what mulbah and I did. | 13:43 |
*** tboimah has quit (Ping timeout: 480 seconds) | 13:44 | |
*** fkoikoi has quit (Ping timeout: 480 seconds) | 13:44 | |
tboimah | sorry my connection drop | 13:45 |
ubuntourist | ok. | 13:46 |
ubuntourist | You type: | 13:46 |
ubuntourist | egrep "qwert" README.md | 13:46 |
ubuntourist | ("qwert" is my "throw-away" word: It's the first five letters on the top row of the keyboard, and is usually something that does not exist.) | 13:47 |
ubuntourist | So. egrep came back with nothing. Which means? | 13:48 |
*** tboimah has quit (Remote host closed the connection) | 13:49 | |
tboimah | sorry oo Mr. cole the connection look bad today | 14:02 |
tboimah | ubuntorurist are you there | 14:03 |
ubuntourist | I'm here | 14:04 |
ubuntourist | I started doing something else while waiting. | 14:04 |
tboimah | okay i am back | 14:04 |
ubuntourist | OK. The tmate is still open. So you should be able to use the up-arrrow to re-enter the ssh command. | 14:06 |
ubuntourist | Oh. | 14:06 |
ubuntourist | Wait. you're alteady here. | 14:06 |
ubuntourist | Sorry. | 14:06 |
tboimah | suer | 14:06 |
tboimah | sure | 14:06 |
ubuntourist | I didn't know you're on. | 14:06 |
ubuntourist | So. egrep came back with nothing. Which means? | 14:07 |
ubuntourist | (egrep "qwert" README.md produced no output. Which means?) | 14:08 |
ubuntourist | ACTION is hoping the connection is still here... If not he is going to just use e-mail for class lectures and hope for the best. | 14:09 |
tboimah | the connection is on | 14:10 |
ubuntourist | There was a question with no response. So I thought the connection was gone again. | 14:10 |
ubuntourist | ACTION continues to wait for an answer to the question ".... Which means?" | 14:12 |
tboimah | "qwert" is your "throw-away" word | 14:12 |
ubuntourist | Yeah, but I mean "When egrep does not produce output, what does that tell you?" | 14:13 |
tboimah | It pretty much means that the string you are searching for was not found | 14:14 |
ubuntourist | Right. | 14:15 |
ubuntourist | OK now "egrep "poet" README.md | 14:15 |
ubuntourist | So. it found some matches. Now try both commands again but this time change "egrep" to "egrep -H". | 14:16 |
ubuntourist | Keep the rest of the line the same. | 14:16 |
ubuntourist | So. What changed? | 14:18 |
tboimah | The name "README.md" come at the begging of the line | 14:19 |
tboimah | and it have so delimiter charater at the to[ | 14:20 |
tboimah | *top | 14:20 |
ubuntourist | If you use grep and egrep to search ONE file only (like we did here) it will not print a file name for matches unless you use the "-H" | 14:20 |
ubuntourist | Now try the commands with "-c" instead of "-H" | 14:20 |
tboimah | it count the number of line | 14:21 |
ubuntourist | Now try both. "-cH" (or "-Hc". the order is not important.) | 14:21 |
ubuntourist | So, you get both the file name and the count. | 14:22 |
tboimah | it print both the file name and count the line | 14:22 |
ubuntourist | When you are looking at lots of files, it can be very helpful to know which files had NO matches. | 14:23 |
ubuntourist | Seeing "filename:0" is better than no output. | 14:24 |
tboimah | yeah | 14:25 |
ubuntourist | "wc -l" either expects a file name after it, or a pipe before it. What it showed you in your second attempt was | 14:25 |
tboimah | sure | 14:25 |
ubuntourist | it tried to count the number of lines in a file named "egrep" and it coud not find a file with that name. Then it tried to find the number of lines in a file named "poet" and it could not find that file. Then it tried to print the number of lines in a file named README.md... and it found that one. | 14:26 |
ubuntourist | And, if you flipped the command around, using the pipe, you would still get a wrong answer. Try: | 14:27 |
ubuntourist | egrep -H "qwert" README.md | wc -l | 14:27 |
ubuntourist | egrep -cH "qwert" README.md | wc -l | 14:28 |
ubuntourist | egrep -cH "poet" README.md | wc -l | 14:29 |
ubuntourist | egrep -cH "QWERT" README.md | wc -l | 14:30 |
ubuntourist | The reason: In the first example, where you just used the -H, egrep printed 15 lines that matched. So "wc -l" said "15" | 14:31 |
ubuntourist | In the second example, where you typed egrep -cH "poet" README.md | wc -l | 14:32 |
ubuntourist | egrep produced as output | 14:32 |
ubuntourist | README.md:1 | 14:32 |
ubuntourist | And you told it to count the number of lines in the output. "README.md:1" is only one line of output. | 14:33 |
tboimah | OKAY. well understood | 14:33 |
ubuntourist | When you used "QWERT", egrep produced "README.md:0" ... which is only one line of output. So "wc -l" again said "1". | 14:34 |
ubuntourist | Now, finally, getting to the example I was trying to work on with mulbah... | 14:35 |
tboimah | okay let role | 14:35 |
ubuntourist | egrep -H "^..To be continued" README.md | 14:35 |
ubuntourist | Now, add a pipe to the end and use cut to split get only the file name. With cut, | 14:37 |
ubuntourist | "-f" follwed by a number tells which field to get and -d followed by a character enclosed in quotes says what the delimiter that separates fields should be | 14:38 |
ubuntourist | (You'll need both a -f and a -d plus a field number and a delimiter.) | 14:39 |
ubuntourist | Nope. the -f needs a number after it and the -d needs a delimiter in quotes after it. | 14:40 |
ubuntourist | Close. Very close. | 14:41 |
ubuntourist | But why did you use 6? | 14:42 |
*** shmohamud has quit (Ping timeout: 480 seconds) | 14:42 | |
tboimah | because you said that -f need a number after it, so i just suggest 6 | 14:43 |
ubuntourist | The field number is the number is the number of which field you want. | 14:43 |
ubuntourist | The field number is the number is the number of which field you want. | 14:44 |
ubuntourist | BINGO. Almost. It worked, but in this situation, just "1" not "-1" would have been better. | 14:46 |
ubuntourist | Let's try a few experiments with that to see why | 14:46 |
ubuntourist | change the delimiter to a space -d " " and use your -1 | 14:47 |
ubuntourist | Try -1 then try 2 and try -2 | 14:48 |
ubuntourist | (leave the -d " " as it is.) | 14:49 |
ubuntourist | ACTION stepping away for a moment. | 14:49 |
mcssguest_ | done | 14:50 |
*** tboimah has quit (Ping timeout: 480 seconds) | 14:51 | |
ubuntourist | ACTION is back. | 14:52 |
tboimah | yeah i done | 14:53 |
ubuntourist | So. In the first one, where we used the space as a delimiter, it did the expected thing: It divided the line by spaces, and printed everything up until the first space. | 14:53 |
ubuntourist | it did that for both "1" and "-1" | 14:54 |
ubuntourist | BUT, for the "2" and "-2" do you have any guess about why they are different? | 14:54 |
tboimah | yeah | 14:54 |
tboimah | i notice the the "-"2 means from the begging of the line to 2 | 14:55 |
ubuntourist | BINGO. | 14:55 |
tboimah | BINGO | 14:56 |
ubuntourist | So, when you use 1 or -1 it means either "field #1" or "from the beginning of the line up until field #1" . And for the first field, those two are the exact same thing. | 14:57 |
ubuntourist | So... We are almost finished with our little Bash program. | 14:58 |
ubuntourist | First we found the file names we wanted to work with. | 14:58 |
ubuntourist | Then for each of those files, we use egrep -H to print the file name, and the match. | 14:59 |
ubuntourist | The pattern here "^[[:space:]]*(poet|composer|arranger)" | 15:00 |
ubuntourist | breaks down like this: | 15:00 |
ubuntourist | ^ at the beginning of the line | 15:00 |
ubuntourist | [[:space:]]* zero or more spaces | 15:00 |
ubuntourist | (poet|composer|arranger) followed by either "poet" or "composer" or "arranger" | 15:01 |
ubuntourist | In other words, find me any lines that start with any of those three words, and nothing before them except spaces. | 15:02 |
ubuntourist | Matching lines would be | 15:02 |
ubuntourist | poet bla-bla-bla | 15:02 |
ubuntourist | composer bla-bla-bla | 15:02 |
ubuntourist | arranger bla-bla-blah | 15:03 |
ubuntourist | poet | 15:03 |
ubuntourist | But not: | 15:03 |
ubuntourist | # poet | 15:03 |
ubuntourist | ; arranger | 15:03 |
ubuntourist | I don't know who the composer is | 15:03 |
ubuntourist | Those last three have the matching words, but they do not start with spaces. | 15:04 |
ubuntourist | I'm going to type to speed things up a little bit. | 15:05 |
ubuntourist | Look at that before hitting the ENTER, because when you press ENTER it's all going to go offf the screen. | 15:07 |
ubuntourist | (When you feel like you've got the basic understanding, press ENTER.) | 15:08 |
ubuntourist | And if you have a question, go ahead and ask before pressing ENTER. | 15:09 |
*** tboimah has quit (Read error: Connection reset by peer) | 15:09 | |
ubuntourist | Hmmm... I must have made a mistake... | 15:09 |
ubuntourist | Hmmm... I must have made a mistake... | 15:09 |
tboimah | done | 15:09 |
ubuntourist | Oh. I know what the problem is: I didn't expand the tarball... Hold a sec... | 15:10 |
ubuntourist | It could not find any files to search because there were no ".ly" files. Now there are. | 15:11 |
ubuntourist | Damn. | 15:11 |
ubuntourist | I'm missing something. | 15:12 |
ubuntourist | Oh.... RIGHT: locate. Locate searches a database. The database has not been updated after I expanded the tarball. | 15:14 |
ubuntourist | locate still does not know that there are any files ending in ".ly"... | 15:14 |
ubuntourist | Hold a sec... | 15:14 |
ubuntourist | One more time... | 15:15 |
ubuntourist | That's what I was looking for.. | 15:15 |
tboimah | yeah BINGO | 15:16 |
ubuntourist | If you scroll left and right you will see the matches. | 15:16 |
ubuntourist | ;-) | 15:16 |
ubuntourist | So. All of the lines contain the full path to the file /home/kjcole/class_notes/.../home/kjcole/.../some_file.ly | 15:17 |
ubuntourist | and the matching text " poet = ..." or " composer = ..." or " arranger = ..." | 15:18 |
ubuntourist | Now, we take the output of the egrep ... and filter it more. We will ELIMINATE lines that have | 15:19 |
ubuntourist | smallCaps | 15:19 |
ubuntourist | in the line. | 15:19 |
ubuntourist | (grep -v "smallCaps") | 15:19 |
ubuntourist | Before we do that, let's find some examples. | 15:20 |
ubuntourist | I don't want the file named "avenging_and_bright.ly" because it has "\smallCaps" | 15:21 |
ubuntourist | The problem that I started with was: | 15:21 |
ubuntourist | I have lots of music files that I created. I want to change the font for the names of poets, or composers, or arrangers to | 15:22 |
ubuntourist | the "Small Capitals" font. | 15:23 |
ubuntourist | But, I have already done that for some files. So I don't need to see those files again. | 15:23 |
ubuntourist | So. Find all the LilyPond files -- (ending with ".ly") that I wrote -- (kjcole) and not fiiles that I downloaded from someone else | 15:24 |
ubuntourist | (FrayedKnotArts or rosegarden or a few other directories) | 15:25 |
ubuntourist | Once I have that list, search each file for poet composer or arranger and eliminate the files that already have the | 15:25 |
ubuntourist | smallCaps. | 15:25 |
ubuntourist | Use "cut" to chop off everything except the file name cut -f 1 -d ":" | 15:27 |
ubuntourist | And finally, "uniq" | 15:27 |
ubuntourist | "uniq" is a command that looks at a sorted list (I probably should have included a "sort" command) | 15:28 |
ubuntourist | and eliminates duplicate lines. It forces the lines to be "unique". | 15:29 |
ubuntourist | See how there are duplicate lines? | 15:30 |
ubuntourist | I have cut off the matching text. | 15:31 |
ubuntourist | Up at the top | 15:31 |
ubuntourist | the first three lines are all the same. | 15:31 |
ubuntourist | Let's go back one step to see why. | 15:32 |
ubuntourist | baritone.ly had three matches: It had a match for poet, a match for composer and a match for arranger. | 15:33 |
ubuntourist | So three lines were printed. | 15:33 |
ubuntourist | When I cut and kept only the file names, I have three identical lines. | 15:33 |
ubuntourist | I only need to know the name of the file once. | 15:34 |
ubuntourist | the list tells me that there is at least ONE line that has a poet or composer or arranger, that does not use smallCaps. | 15:34 |
ubuntourist | It measn that I will need to edit baritone.ly and add \smallCaps to it. | 15:35 |
ubuntourist | I don't need to know that informathon three times. I only need to know "baritone.ly needs editing". | 15:35 |
ubuntourist | Oops. baritone-scale.ly not "baritone.ly" I should read my own screen. ;-) | 15:36 |
ubuntourist | It is getting slower because it has more and more work to do. | 15:37 |
ubuntourist | "sort" and "uniq" can take a long time. | 15:38 |
ubuntourist | now there is only ONE line for each file that meets my criteria. | 15:38 |
ubuntourist | The list on the screen now is the list of files that need to be edited. | 15:38 |
ubuntourist | But we're seeing those in "most" that's not very handy. We want to save the list so we can use it in another Bash program. | 15:39 |
ubuntourist | Instead of "done | most" which sends all of the output into "most" for viewing, | 15:40 |
ubuntourist | "done > add_smallcaps.txt" | 15:40 |
ubuntourist | willl send the results to a new file named "add_smallcaps.txt" | 15:40 |
ubuntourist | The END. ;-) | 15:41 |
tboimah | wow that was great | 15:41 |
tboimah | Thanks very much for today | 15:41 |
ubuntourist | It has been a very, very long story. ;-) | 15:41 |
tboimah | yeah | 15:41 |
tboimah | I understand a lot from it | 15:42 |
ubuntourist | If you can find time, sit with mulbah and help him work through this. But make him do the work | 15:42 |
tboimah | Okay | 15:42 |
ubuntourist | that we did today. He needs to type it and make mistakes like and figure out why things like | 15:43 |
ubuntourist | wc -l egrep "qwert" README,md | 15:43 |
tboimah | got you | 15:43 |
ubuntourist | don't work right. | 15:43 |
ubuntourist | or why an error message keeps saying "cur: no such command" | 15:44 |
ubuntourist | So much of systems administration (and programming) is trying to figure that stuff out. | 15:44 |
ubuntourist | OK. We are WELL over time today. So, I need to run and do other things. | 15:44 |
ubuntourist | BYE! | 15:44 |
tboimah | Thanks for today, and have a nice day. | 15:45 |
*** ubuntourist has quit (Quit: Leaving) | 15:45 | |
*** tboimah has quit (Quit: Leaving) | 15:46 | |
*** scooper has quit (Ping timeout: 480 seconds) | 19:49 | |
*** sysadmin has quit (Ping timeout: 480 seconds) | 19:55 | |
*** sysadmin_ has quit (Ping timeout: 480 seconds) | 19:57 | |
*** janet has quit (None) | 20:02 | |
*** sysadmin_ has quit (None) | 20:13 | |
*** sysadmin__ has quit (None) | 20:14 | |
*** scooper has quit (Ping timeout: 480 seconds) | 20:18 | |
*** scooper has quit (Ping timeout: 480 seconds) | 20:37 | |
shmohamud | Hi Scooper, you there? | 20:37 |
scooper | Hello Sahnun | 20:38 |
scooper | Did you see my mail??? | 20:38 |
shmohamud | Is the commode a bathroom? Where did you drop your phone? | 20:38 |
scooper | yes | 20:38 |
shmohamud | Yes I read it that's how I knew to show up now. | 20:38 |
scooper | it was on change in the bathroom | 20:39 |
shmohamud | I'm sorry about your phone, but it's a funny way to lose a phone :) lol | 20:39 |
shmohamud | When do you think you'll get a replacement? | 20:39 |
scooper | No I didn't lose the phone but water enter in the phone | 20:39 |
shmohamud | Oh, I thought you dropped it into the toilet | 20:40 |
scooper | When the month end I will try to fix it | 20:41 |
shmohamud | Ok, the good news is you don't need a phone to learn javascript and meet with me :) | 20:41 |
shmohamud | So, shall we begin today's lesson? | 20:41 |
scooper | hahaha yes | 20:41 |
scooper | I m ready to tip up my programming knowledge | 20:42 |
shmohamud | Excellent. So as usual, some review of the previously covered topics | 20:42 |
scooper | sure | 20:42 |
shmohamud | Can you write me a function declaration that takes in a parameter of "name" and logs out "Hello {name}" Then call it with any name and let me know if it works. | 20:43 |
scooper | sure | 20:43 |
scooper1 | Hello Sahnun | 20:52 |
scooper1 | are you still there | 20:52 |
shmohamud | yes | 20:53 |
*** scooper has quit (Ping timeout: 480 seconds) | 20:54 | |
shmohamud | all good? | 20:55 |
scooper1 | yes | 20:55 |
*** sysadmin_ has quit (Ping timeout: 480 seconds) | 20:57 | |
scooper | did you see the problem?? | 20:57 |
scooper | solution? | 20:57 |
shmohamud | no can you paste it again? | 20:57 |
scooper | function greetingMessage(name){ | 20:58 |
scooper | console.log("Hello " + name + "thanks for teaching me JS"); | 20:58 |
scooper | } | 20:58 |
scooper | greetingMessage("Sahnun"); | 20:58 |
shmohamud | Well done :) And I like the function name, it simply puts what's happening inside the function. | 20:59 |
shmohamud | The only change I would make would be to call it simply "greet" and call it as greet("Sahnun") | 20:59 |
scooper | ok | 21:00 |
shmohamud | Ok, so here's a new challenge with Arrow Functions. In an arrow function, you don't need to include a return statement if it's only one statement in the function body | 21:00 |
shmohamud | It will automatically return. If you have a multi-statement function, you have to explicitly include a return statement or else it will return undefined | 21:01 |
shmohamud | Are you following me? | 21:01 |
shmohamud | Scooper, are you there? | 21:05 |
shmohamud | Scooper, are you there? | 21:07 |
sysadmin_ | yes | 21:07 |
shmohamud | Ok, did you read the bit about arrow functions? | 21:07 |
sysadmin_ | the question you just post in here?? | 21:08 |
shmohamud | Let me repaste it, it's about arrow functions | 21:08 |
shmohamud | Ok, so here's a new challenge with Arrow Functions. In an arrow function, you don't need to include a return statement if it's only one statement in the function body. | 21:08 |
shmohamud | It will automatically return. If you have a multi-statement function, you have to explicitly include a return statement or else it will return undefined | 21:08 |
sysadmin_ | ok | 21:09 |
*** scooper has quit (Ping timeout: 480 seconds) | 21:09 | |
shmohamud | Are you following so far? | 21:09 |
scooper | yes | 21:09 |
shmohamud | so what does iAmAnArrowFunction = () => { 2+2 } return? | 21:10 |
shmohamud | compare that to iAmAlsoAnArrowFunction = () => 2+2 | 21:12 |
scooper | this is what the function will output if it call | 21:12 |
scooper | () =>{2+2} | 21:12 |
shmohamud | so here's a quick way to know what gets returned | 21:12 |
shmohamud | If there are curly braces in the arrow function, you must include a "return" statement or else it will return undefiend | 21:13 |
*** scooper1 has quit (Ping timeout: 480 seconds) | 21:13 | |
shmohamud | If there are no curly braces and it's only a single statement, you don't need to include a "return" statement | 21:13 |
shmohamud | Still with me? | 21:13 |
shmohamud | U there scooper? | 21:16 |
scooper1 | yes | 21:16 |
scooper1 | I m here sorry my internet keep stripping | 21:16 |
shmohamud | Did you see what I wrote about including the curly braces in an arrow function? | 21:17 |
scooper1 | yes | 21:17 |
scooper1 | but my thought for curly bracket is | 21:17 |
shmohamud | Ok, so what does iAmAnArrowFunction = () => { let sum = 2+2; console.log(sum) } return? | 21:18 |
scooper1 | I was thinking the curly bracket act as the indication for a code block | 21:18 |
shmohamud | Yes, they do for function declarations and *some* arrow functions. | 21:19 |
scooper1 | should I put it in the console or I should look I at and tell the answer | 21:19 |
shmohamud | There are some arrow functions that can be declared with curly brackets | 21:19 |
scooper1 | the output will be 4 | 21:20 |
shmohamud | First, tell me based on the rules I explained, what would the result of iAmAnArrowFunction = () => { let sum = 2+2; console.log(sum) } return? | 21:20 |
*** scooper has quit (Ping timeout: 480 seconds) | 21:21 | |
shmohamud | Output is not that same as the return value. What if I said testSum = iAmAnArrowFunction() | 21:21 |
shmohamud | what would testSum equal? | 21:21 |
scooper1 | if you store the function in a variable the out will be 4 when the variable is called | 21:22 |
shmohamud | I want you to test it and let me know | 21:23 |
shmohamud | can you test it for me? | 21:23 |
scooper1 | ok | 21:23 |
shmohamud | after you set testSum equal to iAmAnArrowFunction I want you to console.log(testSum) | 21:25 |
scooper1 | something like this right ? iAmAnArrowFunction = () =>{ | 21:27 |
scooper1 | let sum = 2+2; | 21:27 |
scooper1 | console.log(sum) | 21:27 |
scooper1 | } | 21:27 |
shmohamud | yes, then set that equal to testSum and console.log(testSum) | 21:28 |
scooper1 | iAmAnArrowFunction = () =>{ | 21:28 |
scooper1 | let sum = 2+2; | 21:28 |
scooper1 | console.log(sum) | 21:28 |
scooper1 | } | 21:28 |
scooper1 | testSum = iAmAnArrowFunction(); | 21:28 |
scooper1 | the output is "4" | 21:29 |
shmohamud | Now, console.log(testSum) and let me know what you see | 21:29 |
shmohamud | what's the value of testSum, not what's getting logged to the console. | 21:29 |
scooper1 | 4 is the output but understand the 4 i m seeming "undefined" | 21:30 |
shmohamud | Exactly, it's undefined. Do you know why? | 21:30 |
scooper1 | 4 is the output but under the 4 i m seeming "underfined | 21:30 |
scooper1 | trying to figure out but seeming complicated | 21:31 |
scooper1 | please hold on | 21:32 |
scooper1 | let try | 21:32 |
shmohamud | can you try something for me? Instead of ending the function with "console.log(sum)" can you add "return sum"? | 21:32 |
scooper1 | sure | 21:32 |
shmohamud | let me know what testSum equals after you set it equal to that. | 21:32 |
shmohamud | Also I'm short on time, I have somewhere to be at 56pm and need to shower. After this we will continue tomorrow. | 21:33 |
scooper1 | ok | 21:33 |
scooper1 | iAmAnArrowFunction = () =>{ | 21:33 |
scooper1 | let sum = 2+2; | 21:33 |
scooper1 | return sum; | 21:33 |
scooper1 | } | 21:33 |
scooper1 | testSum = iAmAnArrowFunction(); | 21:33 |
scooper1 | 4 | 21:33 |
shmohamud | is the output undefined? | 21:33 |
scooper1 | no | 21:33 |
shmohamud | it's 4 right? | 21:34 |
scooper1 | yes | 21:34 |
shmohamud | That's because we added a "return" statement. If you don't include the return statement in an arrow function with curly braces, it will return undefined by default | 21:34 |
shmohamud | Just by console.log(sum) doesn't return anything, you must add the return statement or you will return undefined. | 21:35 |
shmohamud | I know this is rather complex, but are you starting to see how return statements in functions work? | 21:35 |
scooper1 | yes I m seeming it | 21:35 |
scooper1 | but the problem here is that | 21:36 |
scooper1 | whether you use return or console | 21:36 |
shmohamud | For homework, I want you define two arrow functions. One of them should be one line and NOT include a return statement. Just have a value on the line like "Test Val" or "3" | 21:36 |
scooper1 | the expression still display a output | 21:36 |
shmohamud | The second arrow function should include curly braces (the first one should not have curly braces) | 21:37 |
shmohamud | And it should include a return statement, return whatever you'd like as long as it returns. | 21:38 |
shmohamud | console.log will always produce output whether you return it or not | 21:38 |
shmohamud | I've got to run scooper but it's been a pleasure learning with you today. Looking forward to tomorrow. Try to knock out the homework or we'll do it together next class | 21:39 |
scooper1 | ok | 21:39 |
scooper1 | I will do it Sahnun thanks for the time | 21:39 |
scooper1 | see you tomorrow same time | 21:39 |
shmohamud | sounds good, great job today. | 21:41 |
scooper1 | ACTION signing up for today | 21:41 |
*** scooper1 has quit (Quit: Leaving) | 21:42 | |
*** shmohamud has quit (Remote host closed the connection) | 21:51 | |
*** shmohamud has quit (Ping timeout: 480 seconds) | 22:10 | |
*** shmohamud has quit (Ping timeout: 480 seconds) | 23:11 |
Generated by irclog2html.py 2.17.3 by Marius Gedminas - find it at https://mg.pov.lt/irclog2html/!