From e5d88aebd7702648dbabd630528b700a74dd8941 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Sun, 16 Jun 2019 14:37:39 +0200 Subject: [PATCH 01/55] Update jl-errors-formatting.md --- week-1/jl-errors-formatting.md | 35 +++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/week-1/jl-errors-formatting.md b/week-1/jl-errors-formatting.md index 66627fb..39cd87c 100644 --- a/week-1/jl-errors-formatting.md +++ b/week-1/jl-errors-formatting.md @@ -1,3 +1,36 @@ > paste [this markdown](https://raw.githubusercontent.com/janke-learning/error-exercises/master/formatting.md) into this file and fix the errors! > [completed example](https://github.com/AlfiYusrina/hyf-javascript1/blob/master/week1/errors_solutions.MD) (of the old version) -> references: [errors & life-cycle](https://github.com/janke-learning/errors-and-life-cycle), [exercise repo](https://github.com/janke-learning/errors) \ No newline at end of file +> references: [errors & life-cycle](https://github.com/janke-learning/errors-and-life-cycle), [exercise repo](https://github.com/janke-learning/errors) + +# Formatting Errors + +It's easy to miss the little things, even when you're an experienced programmer! Using a linter will help enormously avoiding simple formatting errors, but it's still great practice to learn how to spot them yourself. This skill build your confidence writing code from a blank page and is important for those times when you're coding outside of your normal editor. + +### exercises +* [improper end of statement](#improper-end-of-statement) + +--- + +## improper end of statement +broken code: +```js +let a = 1: +``` +error message: +``` +``` +classification: +* creation phase or execution phase ? +* syntax or semanitc ? + +the fix: +```js +``` +your notes: + +[TOP](#formatting-errors) + + +___ +___ +### Janke Learning From 467e331d1276bbcbd384ef21acd1c9646e7ecd71 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Sun, 16 Jun 2019 14:38:51 +0200 Subject: [PATCH 02/55] Update jl-errors-formatting.md From ef97f543123c3babb57fcfaba76fbc3c87f66175 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Sun, 16 Jun 2019 14:49:17 +0200 Subject: [PATCH 03/55] Update jl-errors-formatting.md --- week-1/jl-errors-formatting.md | 1 + 1 file changed, 1 insertion(+) diff --git a/week-1/jl-errors-formatting.md b/week-1/jl-errors-formatting.md index 39cd87c..32fe50f 100644 --- a/week-1/jl-errors-formatting.md +++ b/week-1/jl-errors-formatting.md @@ -18,6 +18,7 @@ let a = 1: ``` error message: ``` +Uncaught SyntaxError: Unexpected token : ``` classification: * creation phase or execution phase ? From 3fce8d5a9404536fdcdbaba6f4951f4cd2377f0f Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Sun, 16 Jun 2019 14:54:35 +0200 Subject: [PATCH 04/55] Update jl-variables-multiple.md --- week-1/jl-variables-multiple.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/week-1/jl-variables-multiple.md b/week-1/jl-variables-multiple.md index b8bc5f5..92a6f49 100644 --- a/week-1/jl-variables-multiple.md +++ b/week-1/jl-variables-multiple.md @@ -1,2 +1,2 @@ -> paste [this markdown of exercises](https://raw.githubusercontent.com/janke-learning/variable-exercises/master/swaps.md) into this file and complete the exercises! -> references: [javascript.info variables](https://javascript.info/variables), [variables and hoisting](https://github.com/janke-learning/variables-and-hoisting) \ No newline at end of file +> paste [this markdown of exercises](https://raw.githubusercontent.com/janke-learning/variable-exercises/master/multiple-assignments.md) into this file and complete the exercises! +> references: [javascript.info variables](https://javascript.info/variables), [variables and hoisting](https://github.com/janke-learning/variables-and-hoisting) From b18207d4c908ca7bcd626808173d93b904f2beb4 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Sun, 16 Jun 2019 14:58:18 +0200 Subject: [PATCH 05/55] Update jl-variables-multiple.md --- week-1/jl-variables-multiple.md | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/week-1/jl-variables-multiple.md b/week-1/jl-variables-multiple.md index 92a6f49..d5a8279 100644 --- a/week-1/jl-variables-multiple.md +++ b/week-1/jl-variables-multiple.md @@ -1,2 +1,39 @@ > paste [this markdown of exercises](https://raw.githubusercontent.com/janke-learning/variable-exercises/master/multiple-assignments.md) into this file and complete the exercises! > references: [javascript.info variables](https://javascript.info/variables), [variables and hoisting](https://github.com/janke-learning/variables-and-hoisting) + +# Swaps + +You'll be given a bunch of variables with the wrong value assigned and a temporary variable you can use for storing values. Your task is to get the right values into each variable in as few steps as possible by shuffling them around. + +### example solutions +1. the first: [pytut](https://goo.gl/mk9xd3), [parsons](https://janke-learning.github.io/parsonizer/?snippet=let%20a%20%3D%20%22b%22%2C%20b%20%3D%20%22a%22%3B%0Alet%20_%20%3D%20'%20'%3B%0A%0A_%20%3D%20b%3B%0Ab%20%3D%20a%3B%0Aa%20%3D%20_%3B) +1. the second: [pytut](https://goo.gl/BWKuGm), [parsons](https://janke-learning.github.io/parsonizer/?snippet=let%20a%20%3D%20%22c%22%2C%20b%20%3D%20%22a%22%2C%20c%20%3D%20%22b%22%3B%0Alet%20_%20%3D%20'%20'%3B%0A%0A_%20%3D%20c%3B%0Ac%20%3D%20a%3B%0Aa%20%3D%20b%3B%0Ab%20%3D%20_%3B%0A) +1. the third: [pytut](https://goo.gl/jeBHWU), [parsons](https://janke-learning.github.io/parsonizer/?snippet=let%20a%20%3D%20%22d%22%2C%20b%20%3D%20%22a%22%2C%20c%20%3D%20%22b%22%2C%20d%20%3D%20%22c%22%3B%0Alet%20_%20%3D%20'%20'%3B%0A%0A_%20%3D%20a%3B%0Aa%20%3D%20b%3B%0Ab%20%3D%20c%3B%0Ac%20%3D%20d%3B%0Ad%20%3D%20_%3B%0A) +1. the fourth: [pytut](https://goo.gl/C8t81i), [parsons](https://janke-learning.github.io/parsonizer/?snippet=let%20a%20%3D%20%22z%22%2C%20b%20%3D%20%22y%22%2C%20c%20%3D%20%22x%22%2C%20d%20%3D%20%22w%22%3B%0Alet%20_%20%3D%20'%20'%3B%0A%0A_%20%3D%20a%3B%0Aa%20%3D%20d%3B%0Ad%20%3D%20_%3B%0A_%20%3D%20b%3B%0Ab%20%3D%20c%3B%0Ac%20%3D%20_%3B%0A) +1. the fifth: [pytut](https://goo.gl/KokxwL), [parsons](https://janke-learning.github.io/parsonizer/?snippet=let%20a%20%3D%20%22z%22%2C%20b%20%3D%20%22y%22%2C%20c%20%3D%20%22x%22%2C%20d%20%3D%20%22w%22%2C%20e%20%3D%20%22v%22%3B%0Alet%20_%20%3D%20'%20'%3B%0A%0A_%20%3D%20a%3B%0Aa%20%3D%20e%3B%0Ae%20%3D%20_%3B%0A_%20%3D%20b%3B%0Ab%20%3D%20d%3B%0Ad%20%3D%20_%3B%0A) + +### challenges +1. [the first](https://goo.gl/k9jdZy) +```js +// your solution here +``` +1. [the second](https://goo.gl/KvayUU) +```js +// your solution here +``` +1. [the third](https://goo.gl/WXXtV7) +```js +// your solution here +``` +1. [the fourth](https://goo.gl/nTA1DG) +```js +// your solution here +``` +1. [the fifth](https://goo.gl/gDaKNi) +```js +// your solution here +``` + +___ +___ +### Janke Learning From c8d07e69196ec9f8b1e71ff3b88de8acf7c069b3 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Sun, 16 Jun 2019 15:11:27 +0200 Subject: [PATCH 06/55] Update jl-variables-swaps.md --- week-1/jl-variables-swaps.md | 62 +++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/week-1/jl-variables-swaps.md b/week-1/jl-variables-swaps.md index 50ccca2..f205e13 100644 --- a/week-1/jl-variables-swaps.md +++ b/week-1/jl-variables-swaps.md @@ -1,2 +1,62 @@ > paste [this markdown of exercises](https://raw.githubusercontent.com/janke-learning/variable-exercises/master/multiple-assignments.md) into this file and complete the exercises! -> references: [javascript.info variables](https://javascript.info/variables), [variables and hoisting](https://github.com/janke-learning/variables-and-hoisting) \ No newline at end of file +> references: [javascript.info variables](https://javascript.info/variables), [variables and hoisting](https://github.com/janke-learning/variables-and-hoisting) + +# Multiple Assignments + +There are mechanisms for assigning multiple variables on one line: +* _chaining assignments_ - ```a = b = c = 4;``` +* _comma-separated assignments_ - ```a = 1, b = 2, c = 3;``` + +These exercises will help you practice multiple assignments on one line: +1. [chaining assignments](#chaining-assignments) +1. [comma-separated assignments](#comma-separated-assignments) + +--- + +## Chaining Assignments + +### completed examples +* the first: [pytut](http://www.pythontutor.com/javascript.html#code=var%20a%20%3D%20'b'%3B%0Avar%20b1%20%3D%20'a',%20b2%20%3D%20'a'%3B%0Avar%20_%20%3D%20''%3B%0A%0A_%20%3D%20b1%3B%0Ab1%20%3D%20b2%20%3D%20a%3B%0Aa%20%3D%20_%3B&curInstr=0&mode=display&origin=opt-frontend.js&py=js&rawInputLstJSON=%5B%5D), [parsonized](https://janke-learning.github.io/parsonizer/?snippet=var%20a%20%3D%20'b'%3B%0Avar%20b1%20%3D%20'a'%2C%20b2%20%3D%20'a'%3B%0Avar%20_%20%3D%20''%3B%0A%0A_%20%3D%20b1%3B%0Ab1%20%3D%20b2%20%3D%20a%3B%0Aa%20%3D%20_%3B) +* the second: [pytut](http://www.pythontutor.com/javascript.html#code=var%20a%20%3D%20'c'%3B%0Avar%20b1%20%3D%20'a',%20b2%20%3D%20'a'%3B%0Avar%20c1%20%3D%20'b',%20c2%20%3D%20'b',%20c3%3B%0Ac3%20%3D%20'b'%3B%0Avar%20_%20%3D%20''%3B%0A%0A_%20%3D%20a%3B%0Aa%20%3D%20b1%3B%0Ab1%20%3D%20b2%20%3D%20c1%3B%0Ac1%20%3D%20c2%20%3D%20c3%20%3D%20_%3B&curInstr=0&mode=display&origin=opt-frontend.js&py=js&rawInputLstJSON=%5B%5D), +[parsonized](https://janke-learning.github.io/parsonizer/?snippet=var%20a%20%3D%20'c'%3B%0Avar%20b1%20%3D%20'a'%2C%20b2%20%3D%20'a'%3B%0Avar%20c1%20%3D%20'b'%2C%20c2%20%3D%20'b'%2C%20c3%3B%0Ac3%20%3D%20'b'%3B%0Avar%20_%20%3D%20''%3B%0A%0A_%20%3D%20a%3B%0Aa%20%3D%20b1%3B%0Ab1%20%3D%20b2%20%3D%20c1%3B%0Ac1%20%3D%20c2%20%3D%20c3%20%3D%20_%3B) + +### exercises +* [the first](http://www.pythontutor.com/live.html#code=var%20a%20%3D%20'b'%3B%0Avar%20b1%20%3D%20'a',%20b2%20%3D%20'a'%3B%0Avar%20_%20%3D%20''%3B%0A%0A//%20--%20can%20be%20done%20in%203%20lines&cumulative=false&curInstr=3&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) +```js +// your solution here +``` +* [the second](http://www.pythontutor.com/live.html#code=var%20a%20%3D%20'c'%3B%0Avar%20b1%20%3D%20'a',%20b2%20%3D%20'a'%3B%0Avar%20c1%20%3D%20'b',%20c2,%20c3%3B%0Ac2%20%3D%20'b',%20c3%20%3D%20'b'%3B%0Avar%20_%20%3D%20''%3B%0A%0A//%20---%20can%20be%20done%20in%204%20lines%20---&cumulative=false&curInstr=5&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) +```js +// your solution here +``` + +[TOP](#multiple-assignments) + +--- + +## Comma-Separated Assignments + +### completed examples +* basic swap: [pytut](http://www.pythontutor.com/javascript.html#code=var%20a%20%3D%20'b',%20b%20%3D%20'a'%3B%0Avar%20_%20%3D%20''%3B%0A%0A_%20%3D%20a,%20a%20%3D%20b,%20b%20%3D%20_%3B&curInstr=0&mode=display&origin=opt-frontend.js&py=js&rawInputLstJSON=%5B%5D), [parsonized](https://janke-learning.github.io/parsonizer/?snippet=var%20a%20%3D%20'b'%2C%20b%20%3D%20'a'%3B%0Avar%20_%20%3D%20''%3B%0A%0A_%20%3D%20a%2C%20a%20%3D%20b%2C%20b%20%3D%20_%3B) +* double swap - two lines: [pytut](http://www.pythontutor.com/javascript.html#code=var%20a,%20b,%20c%3B%0Aa%20%3D%20'b',%20b%20%3D%20'c',%20c%20%3D%20'a'%3B%0Avar%20_%20%3D%20''%3B%0A%0A_%20%3D%20a,%20a%20%3D%20c%3B%0Ac%20%3D%20b,%20b%20%3D%20_%3B&curInstr=0&mode=display&origin=opt-frontend.js&py=js&rawInputLstJSON=%5B%5D), [parsonized](https://janke-learning.github.io/parsonizer/?snippet=var%20a%2C%20b%2C%20c%3B%0Aa%20%3D%20'b'%2C%20b%20%3D%20'c'%2C%20c%20%3D%20'a'%3B%0Avar%20_%20%3D%20''%3B%0A%0A_%20%3D%20a%2C%20a%20%3D%20c%3B%0Ac%20%3D%20b%2C%20b%20%3D%20_%3B) +* double swap - one line: [pytut](http://www.pythontutor.com/javascript.html#code=var%20a,%20b%20%3D%20'c',%20c%20%3D%20'a'%3B%0Aa%20%3D%20'b'%3B%0Avar%20_%20%3D%20''%3B%0A%0A_%20%3D%20a,%20a%20%3D%20c,%20c%20%3D%20b,%20b%20%3D%20_%3B&curInstr=0&mode=display&origin=opt-frontend.js&py=js&rawInputLstJSON=%5B%5D), [parsonized](https://janke-learning.github.io/parsonizer/?snippet=var%20a%2C%20b%20%3D%20'c'%2C%20c%20%3D%20'a'%3B%0Aa%20%3D%20'b'%3B%0Avar%20_%20%3D%20''%3B%0A%0A_%20%3D%20a%2C%20a%20%3D%20c%2C%20c%20%3D%20b%2C%20b%20%3D%20_%3B) + +### exercises +* [basic swap](http://www.pythontutor.com/live.html#code=var%20a%20%3D%20'b',%20b%20%3D%20'a'%3B%0Avar%20_%20%3D%20''%3B%0A%0A//%20---%20solve%20this%20in%20one%20line%20---&cumulative=false&curInstr=2&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) +```js +// your solution here +``` +* [double swap - two lines](http://www.pythontutor.com/live.html#code=var%20a,%20b,%20c%3B%0Aa%20%3D%20'b',%20b%20%3D%20'c',%20c%20%3D%20'a'%3B%0Avar%20_%20%3D%20''%3B%0A%0A//%20---%20solve%20this%20in%202%20lines%20---&cumulative=false&curInstr=3&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) +```js +// your solution here +``` +* [double swap - one line](http://www.pythontutor.com/live.html#code=var%20a%20%3D%20'b',%20b%20%3D%20'c',%20c%20%3D%20'a'%3B%0Avar%20_%20%3D%20''%3B%0A%0A_%20%3D%20a,%20a%20%3D%20c,%20c%20%3D%20b,%20b%20%3D%20_%3B&cumulative=false&curInstr=3&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) +```js +// your solution here +``` + +[TOP](#multiple-assignments) + +___ +___ +### Janke Learning From fbee52b4cac02eaded82eac4685f239559a1a939 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Sun, 16 Jun 2019 15:13:49 +0200 Subject: [PATCH 07/55] 1 11 --- week-1/jl-variables-swaps.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/week-1/jl-variables-swaps.md b/week-1/jl-variables-swaps.md index f205e13..48a763e 100644 --- a/week-1/jl-variables-swaps.md +++ b/week-1/jl-variables-swaps.md @@ -1,6 +1,7 @@ > paste [this markdown of exercises](https://raw.githubusercontent.com/janke-learning/variable-exercises/master/multiple-assignments.md) into this file and complete the exercises! > references: [javascript.info variables](https://javascript.info/variables), [variables and hoisting](https://github.com/janke-learning/variables-and-hoisting) + # Multiple Assignments There are mechanisms for assigning multiple variables on one line: @@ -60,3 +61,4 @@ These exercises will help you practice multiple assignments on one line: ___ ___ ### Janke Learning + From 5a0e785cbbb39b6fb26f105bcea5a588bd132b28 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Sun, 16 Jun 2019 15:14:56 +0200 Subject: [PATCH 08/55] Rename jl-variables-swaps.md to jl-variables-multiple1.md --- week-1/{jl-variables-swaps.md => jl-variables-multiple1.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename week-1/{jl-variables-swaps.md => jl-variables-multiple1.md} (100%) diff --git a/week-1/jl-variables-swaps.md b/week-1/jl-variables-multiple1.md similarity index 100% rename from week-1/jl-variables-swaps.md rename to week-1/jl-variables-multiple1.md From f019dcbb364d4faa60031760ffb1f04a412efb8c Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Sun, 16 Jun 2019 15:15:26 +0200 Subject: [PATCH 09/55] Rename jl-variables-multiple.md to jl-variables-swaps.md --- week-1/{jl-variables-multiple.md => jl-variables-swaps.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename week-1/{jl-variables-multiple.md => jl-variables-swaps.md} (100%) diff --git a/week-1/jl-variables-multiple.md b/week-1/jl-variables-swaps.md similarity index 100% rename from week-1/jl-variables-multiple.md rename to week-1/jl-variables-swaps.md From b7d2d74cb099754b02a70963e4de6d3145bb25dd Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Sun, 16 Jun 2019 15:39:21 +0200 Subject: [PATCH 10/55] Update fcc-basic-js-pt-1.md --- week-1/fcc-basic-js-pt-1.md | 592 ++++++++++++++++++++++++++++++++++++ 1 file changed, 592 insertions(+) diff --git a/week-1/fcc-basic-js-pt-1.md b/week-1/fcc-basic-js-pt-1.md index 6ca5118..7bbed2a 100644 --- a/week-1/fcc-basic-js-pt-1.md +++ b/week-1/fcc-basic-js-pt-1.md @@ -1,3 +1,595 @@ > complete [the basic JS exercises](https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript) through _Counting Cards_ & paste each of your solutions into this file. This will allow you to use your FCC exercises as a study reference later on > [completed example](https://github.com/AlfiYusrina/hyf-javascript1/blob/master/week1/freecode_camp_solutions.MD) +# First Part Homework + +[My FreeCodeCamp Portfolio](https://www.freecodecamp.org/alfiyusrina) +## 1. Comment Your Code + +```js +// this is my first comment +/* this is a multi line comment */ +``` + +## 2. Declare Variables +```js +var myName; +``` + +## 3.Storing Values with the Assignment Operator +```js +a = 7; +b = a; +a = b; +``` + +## 4. Initializing Variables with the Assignment Operator +```js +var a = 9; +``` + +## 5. Understanding Uninitialized Variables +```js +var a = 5; +var b = 10; +var c = "I am a"; +``` +## 6. Understanding Case Sensitivity in Variables +```js +// Declarations +var studlyCapVar; +var properCamelCase; +var titleCaseOver; + +// Assignments +studlyCapVar = 10; +properCamelCase = "A String"; +titleCaseOver = 9000; +``` + +## 7.Add Two Numbers (+) +```js +var sum = 10 + 0; +sum = 10 + 10; +``` +## 8. Subtract One Number from Another +```js +var difference = 45 - 33; +``` +## 9. Multiply Two Numbers +```js +var product = 8 * 10; +``` +## 10. Divide One Number by Another (/) +```js +var quotient = 66 / 33; +``` +## 11 .Increment a Number (i++) + +```js +var myVar = 87; +myVar++; +``` + +## 12. Decrement a Number (i--) +```js +myVar--; +``` + + +## 13. Create Decimal Numbers +```js +var myDecimal = 8.8; +``` + +## 14. Multiply Two Decimals +```js +var product = 2.0 * 2.5; +``` + +## 15. Divide One Decimal by Another +```js +var quotient = 4.4 / 2.0; +``` +## 16. Finding a Remainder +```js +var remainder; +remainder = 11 % 3; +``` +## 17. Compound Assignment With Augmented Addition (+=) +```js +a += 12; +b += 9; +c += 7; +``` +## 18. Compound Assignment With Augmented Subtraction (-=) + +```js +a -= 6; +b -= 15; +c -= 1; +``` +## 19. Compound Assignment With Augmented Multiplication +```js +a *= 5; +b *= 3; +c *= 10; +``` +## 20. Compound Assignment With Augmented Division +```js +a /= 12; +b /= 4; +c /= 11; +``` + +## 21. Declare String Variables +with ``` " " ``` +```js +var myFirstName = "Alfi"; +var myLastName = "Yusrina"; +``` + +## 22. Escaping Literal Quotes in Strings +Using *backlash* ```\``` in the beginning and in the end of your quotes. +```js +var myStr = "I am a \"double quoted\" string inside \"double quotes\"."; +``` +## 23. Quoting Strings with Single Quotes +String values in JS may be written with single or double quotes. +```js +var myStr = 'Link'; +``` + +## 24. Escape Sequences in Strings +Reasons to use escaping characters: +- is to allow you to use characters you might not otherwise be able to type out, such as a backspace. +- is to allow you to represent multiple quotes in a string without JS misinterpreting what you mean. + +```js +var myStr = 'FirstLine\n\t\\SecondLine\nThirdLine'; +``` + +## 25. Concatenating Strings with Plus Operator +```js +var myStr = "This is the start. " + "This is the end."; +``` +## 26. Concatenating Strings with the Plus Equals Operator +```js +var myStr = "This is the first sentence. "; +myStr += "This is the second sentence."; +``` +## 27. Constructing Strings with Variables +```js +var myStr = "My name is " + myName + " and I am well!"; +``` +## 28. Appending Variables to Strings +```js +var someAdjective = "boring"; +var myStr = "Learning to code is "; +myStr += someAdjective; +``` +## 29. Find the Length of a String +```js +lastNameLength = lastName.length; +``` +## 30. Use Bracket Notation to Find the First Character in a String +```js +firstLetterOfLastName = lastName[0]; +``` +## 31. Understand String Immutability +String values are *immutable*, means that they cannot be altered once created. +```js +myStr = "Hello World"; +``` +## 32. Use Bracket Notation to Find the Nth Character in a String +```js +var thirdLetterOfLastName = lastName[2]; +``` +## 33. Use Bracket Notation to Find the Last Character in a String +Use ```.length-1``` +```js +var lastLetterOfLastName = lastName[lastName.length-1]; +``` +## 34. Use Bracket Notation to Find the Nth-to-Last Character in a String +```js +var secondToLastLetterOfLastName = lastName[lastName.length - 2]; +``` +## 35. Word Blanks +```js +function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) { + var result = "The " + myAdjective + " " + myNoun + " " + myVerb + " " + myAdverb + "."; + return result; +} +wordBlanks("cat", "little", "hit", "slowly"); +``` +## 36. Store Multiple Values in one Variable using JavaScript Arrays +Array variables for storing several pieces of data in one place. +```js +var myArray = ["Alfi", 28]; +``` +## 37. Nest one Array within Another Array +```js +var myArray = [["Bulls", 23], ["White Sox", 45]]; +``` +## 39. Modify Array Data With Indexes +```js +myArray[0] = 45; +``` +## 40. Access Multi-Dimensional Arrays With Indexes +```js +var myData = myArray[2][1]; +``` +## 41. Manipulate Arrays With push() +Adding an extra to the last array. +```js +myArray.push(["dog", 3]); +``` +## 42. Manipulate Arrays With pop() +You can pop off the last array, and store it in a variable. +```js +var removedFromMyArray = myArray.pop(); +``` +## 43. Manipulate Arrays With shift() +removing the first in the array +```js +var removedFromMyArray = myArray.shift(); +``` +## 44. Manipulate Arrays With unshift() +Adding an extra to the first in the array. +```js +var myArray = [["John", 23], ["dog", 3]]; +myArray.shift(); + +myArray.unshift(["Paul",35]); +``` +## 45. Shopping List +```js +var myList = [["rice", 5] , ["bread", 6] , ["cake", 7], [ "quinoa", 9], ["potato", 20]]; +``` +## 46. Write Reusable JavaScript with Functions +```js +function reusableFunction() { + console.log("Hi World"); +} + +reusableFunction(); +``` +## 47. Passing Values to Functions with Arguments +```js +function functionWithArgs (a , b) { +console.log(a + b); +} +functionWithArgs (1 , 2); +functionWithArgs (7 , 9); +``` +## 48. Global Scope and Functions +Scope refers to the visibility of variables. +Variables which are defined **outside of a function block** have **Global scope**. +Variables which are used **without the ```var```** keyword are automatically created in the ```global``` scope. This can create unintended consequences elsewhere in your code or when running a function again. You should always declare your variables with ```var```. +```js +var myGlobal = 10; +function fun1() { + oopsGlobal = 5; +} +``` +## 49. Local Scope and Functions +```js +function myLocalScope() { +var myVar = 'use strict'; +} +myLocalScope(); +``` +## 50. Global vs. Local Scope in Functions +```js +var outerWear = "T-Shirt"; +function myOutfit() { + var outerWear = "sweater"; + return outerWear; +} +myOutfit(); +``` +## 51. Return a Value from a Function with Return +Use a ```return``` statement to send a value back out of a function. +```js +function timesFive (num) { + return num * 5; +} +timesFive(5); +timesFive(2); +timesFive(0); +``` +## 52. Understanding Undefined Value returned from a Function +```js +function addFive() { + sum = sum + 5; +} +``` +## 53. Assignment with a Returned Value +```js +var processed = 0; +function processArg(num) { + return (num + 3) / 5; +} +processed = processArg(7); +``` +## 54. Stand in Line + A **queue** is an abstract Data Structure where items are kept in order. + New items can be added (```push```) at the back of the queue and old items are taken off (```shift```) from the front of the queue. + +Add the number to the end of the array = ```push``` +Remove the first element of the array = ```shift``` +Then return the element that was removed = using ```return```. +```js +function nextInLine(arr, item) { + arr.push(item); + return arr.shift(); +} +``` +## 55. Understanding Boolean Values +```js +function welcomeToBooleans() { +return true; +} +``` +## 56. Use Conditional Logic with If Statements +```js +function trueOrFalse(wasThatTrue) { + if (wasThatTrue) { + return "Yes, that was true"; + } + return "No, that was false"; +} +trueOrFalse(true); +``` +## 57. Comparison with the Equality Operator +```js +function testEqual(val) { + if (val == 12) { + return "Equal"; + } + return "Not Equal"; +} +testEqual(12); +``` +## 58. Comparison with the Strict Equality Operator +However, unlike the equality operator, which attempts to convert both values being compared to a common type, the strict equality operator does not perform a type conversion. + +If the values being compared have different types, they are considered unequal, and the strict equality operator will return false. +```js +function testStrict(val) { + if (val === 7) { + return "Equal"; + } + return "Not Equal"; +} +testStrict(10); +``` +## 59. Practice comparing different values +```js +function compareEquality(a, b) { + if (a === b) { + return "Equal"; + } + return "Not Equal"; +} +compareEquality(10, "10"); +``` +## 60. Comparison with the Inequality Operator +```js +function testNotEqual(val) { + if (val != 99) { + return "Not Equal"; + } + return "Equal"; +} +testNotEqual(10); +``` +## 61. Comparison with the Strict Inequality Operator +```js +function testStrictNotEqual(val) { + if (val !== 17) { + return "Not Equal"; + } + return "Equal"; +} + +testStrictNotEqual(10); +``` +## 62. Comparison with the Greater Than Operator +```js +function testGreaterThan(val) { + if (val > 100) { + return "Over 100"; + } + + if (val > 10) { + return "Over 10"; + } + + return "10 or Under"; +} + +testGreaterThan(10); +``` +## 63. Comparison with the Greater Than Or Equal To Operator +```js +function testGreaterOrEqual(val) { + if (val >= 20) { + return "20 or Over"; + } + + if (val >= 10) { + return "10 or Over"; + } + + return "Less than 10"; +} + + +testGreaterOrEqual(10); +``` +## 64. Comparison with the Less Than Operator +```js +function testLessThan(val) { + if (val < 25) { + return "Under 25"; + } + + if (val < 55) { + return "Under 55"; + } + + return "55 or Over"; +} + +testLessThan(10); +``` +## 65. Comparison with the Less Than Or Equal To Operator +```js +function testLessOrEqual(val) { + if (val <= 12) { + return "Smaller Than or Equal to 12"; + } + + if (val <=24) { + return "Smaller Than or Equal to 24"; + } + + return "More Than 24"; +} + +testLessOrEqual(10); + +``` +## 66. Comparison with the Logical And Operator +```js +function testLogicalAnd(val) { + + if (val >= 25 && val <= 50) { + return "Yes"; + } + + return "No"; +} + + +testLogicalAnd(10); +``` +## 67. Comparison with the Logical Or Operator +```js +function testLogicalOr(val) { + + + if (val < 10 || val > 20 ) { + + return "Outside"; + } + + return "Inside"; +} + + +testLogicalOr(15); +``` +## 68. Introducing Else Statements + +```js +function testElse(val) { + var result = ""; + + if (val > 5) { + result = "Bigger than 5"; + } + + else { + result = "5 or Smaller"; + } + + + return result; +} + + +testElse(4); + +``` +## 69. Introducing Else If Statements +```js +function testElseIf(val) { + if (val > 10) { + return "Greater than 10"; + } + + else if (val < 5) { + return "Smaller than 5"; + } + else { + return "Between 5 and 10"; + } + +} + +testElseIf(7); + +``` +## 70. Logical Order in If Else Statements +```js +function orderMyLogic(val) { + if (val < 5) { + return "Less than 5"; + } else if (val < 10) { + return "Less than 10"; + } else { + return "Greater than or equal to 10"; + } +} + +orderMyLogic(7); +``` +## 71. Chaining If Else Statements +```js +function testSize(num) { + if(num < 5) { + return "Tiny"; + } else if (num < 10) { + return "Small"; + } else if (num < 15) { +return "Medium"; + } else if (num < 20) { +return "Large"; + } else if ( num >= 20 ) { + return "Huge"; + } else { + return "Change Me"; } + +} + +testSize(7); +``` +## 72. Golf Code +```js +var names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"]; +function golfScore(par, strokes) { + if (strokes == 1) { +return "Hole-in-one!"; + } else if (strokes <= par - 2) { + return "Eagle" ; + } else if (strokes == par - 1) { + return "Birdie" ; + } else if (strokes == par) { + return "Par" ; + } else if (strokes == par + 1) { + return "Bogey" ; + } else if (strokes == par + 2) { + return "Double Bogey" ; + } else if (strokes >= par + 3) { + return "Go Home!" ; + } else { + return "Change Me"; + } +} + +golfScore(5, 4); +``` + +Resource: [freeCodeCamp](https://www.freecodecamp.org/) From 2d2eea47715aca6b280d6dc59c1176adbf883e1c Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Sun, 16 Jun 2019 15:42:06 +0200 Subject: [PATCH 11/55] Update fcc-basic-js-pt-1.md --- week-1/fcc-basic-js-pt-1.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/week-1/fcc-basic-js-pt-1.md b/week-1/fcc-basic-js-pt-1.md index 7bbed2a..99aef64 100644 --- a/week-1/fcc-basic-js-pt-1.md +++ b/week-1/fcc-basic-js-pt-1.md @@ -6,10 +6,13 @@ [My FreeCodeCamp Portfolio](https://www.freecodecamp.org/alfiyusrina) ## 1. Comment Your Code -```js +``` +js // this is my first comment /* this is a multi line comment */ -``` +``/* This is a +multi-line comment */ +// This is an in-line comment.` ## 2. Declare Variables ```js From b45e750acda9e41d2aa8bf5a14b9650b64b62023 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Thu, 20 Jun 2019 16:53:58 +0200 Subject: [PATCH 12/55] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5c4f179..158297c 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ | emoji | who uses it | meaning | | --- | --- | --- | -| :wavy_dash: | student | started, in progress | +| :wavy_dash: | student | started, in progress | | :question: | student | need help (after asking your fellow students!) | | :white_check_mark: | student | you think it's done, check please! | | :white_check_mark: | coaches | homework is checked and OK | @@ -30,6 +30,7 @@ | :shipit: | coaches | there's an answer to your question, in the comments and/or an issue | | :star2: | coaches | you did something awesome | +| :wavy_dash: | student | started, in progress | --- ## priority guide From eb98f443c2812ac1566aa44fb039442c7bb4fd3b Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Thu, 20 Jun 2019 17:05:20 +0200 Subject: [PATCH 13/55] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 158297c..307067b 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,7 @@ | :warning: | coaches | homework has a few issues, see comments and keep in touch on a new issue | | :shipit: | coaches | there's an answer to your question, in the comments and/or an issue | | :star2: | coaches | you did something awesome | - -| :wavy_dash: | student | started, in progress | +| :wavy_dash: | Kelemu | started, in progress | --- ## priority guide From 1fbe694ccba4f60583e00fb55ac023643e73129f Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Thu, 20 Jun 2019 17:43:53 +0200 Subject: [PATCH 14/55] starting reading --- week-1/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-1/README.md b/week-1/README.md index 062bb4d..edd8089 100644 --- a/week-1/README.md +++ b/week-1/README.md @@ -19,7 +19,7 @@ | emoji | who uses it | meaning | | --- | --- | --- | -| :wavy_dash: | student | started, in progress | +| :wavy_dash: | kelemu | started, in progress | | :question: | student | need help (after asking your fellow students!) | | :white_check_mark: | student | you think it's done, check please! | | :white_check_mark: | coaches | homework is checked and OK | From 77e2c4b293dde3d998ee51e2622be154cfdb78b1 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Thu, 20 Jun 2019 17:50:17 +0200 Subject: [PATCH 15/55] Update README.md --- week-1/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-1/README.md b/week-1/README.md index edd8089..b09d6ff 100644 --- a/week-1/README.md +++ b/week-1/README.md @@ -2,7 +2,7 @@ | | your Emoji | your comments | coach emoji | coach comments | | --- | --- | --- | --- | --- | -| :seedling: __[fcc basics](./fcc-basic-js-pt-1.md)__: through ```Counting Cards``` | | | | | +| :seedling: __[fcc basics](./fcc-basic-js-pt-1.md)__: through ```Counting Cards``` |wavy_dash: |kelemu | started, in progress | | | :dash: __[fcc debugging](./fcc-debugging.md)__ | | | | | | :seedling: __[errors: formatting](./jl-errors-formatting.md)__ | | | | | | :seedling: __[errors: primitives](./jl-errors-primitive-types.md)__ | | | | | From 4e50234b664b3dd56bb847f3b13b02bc5115a5a7 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Thu, 20 Jun 2019 17:51:13 +0200 Subject: [PATCH 16/55] Update README.md --- week-1/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-1/README.md b/week-1/README.md index b09d6ff..03f5c2e 100644 --- a/week-1/README.md +++ b/week-1/README.md @@ -2,7 +2,7 @@ | | your Emoji | your comments | coach emoji | coach comments | | --- | --- | --- | --- | --- | -| :seedling: __[fcc basics](./fcc-basic-js-pt-1.md)__: through ```Counting Cards``` |wavy_dash: |kelemu | started, in progress | | +| :seedling: __[fcc basics](./fcc-basic-js-pt-1.md)__: through ```Counting Cards``` | | | | | | :dash: __[fcc debugging](./fcc-debugging.md)__ | | | | | | :seedling: __[errors: formatting](./jl-errors-formatting.md)__ | | | | | | :seedling: __[errors: primitives](./jl-errors-primitive-types.md)__ | | | | | From de24a59da2a4a1bbd33957cfa82a1181109c0d54 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Fri, 21 Jun 2019 00:30:46 +0200 Subject: [PATCH 17/55] Update fcc-basic-js-pt-1.md --- week-1/fcc-basic-js-pt-1.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/week-1/fcc-basic-js-pt-1.md b/week-1/fcc-basic-js-pt-1.md index 99aef64..9f8ccf4 100644 --- a/week-1/fcc-basic-js-pt-1.md +++ b/week-1/fcc-basic-js-pt-1.md @@ -24,6 +24,11 @@ var myName; a = 7; b = a; a = b; + +a=7; +b=a; +a=b + ``` ## 4. Initializing Variables with the Assignment Operator From ed34580c77b9dc0a84207b220568507673342e23 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Fri, 21 Jun 2019 22:14:12 +0200 Subject: [PATCH 18/55] Update README.md --- week-1/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-1/README.md b/week-1/README.md index 03f5c2e..c1da9ec 100644 --- a/week-1/README.md +++ b/week-1/README.md @@ -2,7 +2,7 @@ | | your Emoji | your comments | coach emoji | coach comments | | --- | --- | --- | --- | --- | -| :seedling: __[fcc basics](./fcc-basic-js-pt-1.md)__: through ```Counting Cards``` | | | | | +| :seedling: __[fcc basics](./fcc-basic-js-pt-1.md)__: through ```Counting Cards``` |:wavy_dash: | | | | | :dash: __[fcc debugging](./fcc-debugging.md)__ | | | | | | :seedling: __[errors: formatting](./jl-errors-formatting.md)__ | | | | | | :seedling: __[errors: primitives](./jl-errors-primitive-types.md)__ | | | | | From c22ae8dad9739a011e7cf162e85691e3f816f722 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Fri, 21 Jun 2019 23:56:12 +0200 Subject: [PATCH 19/55] Update fcc-basic-js-pt-1.md --- week-1/fcc-basic-js-pt-1.md | 61 +++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/week-1/fcc-basic-js-pt-1.md b/week-1/fcc-basic-js-pt-1.md index 9f8ccf4..4d09b5f 100644 --- a/week-1/fcc-basic-js-pt-1.md +++ b/week-1/fcc-basic-js-pt-1.md @@ -34,6 +34,9 @@ a=b ## 4. Initializing Variables with the Assignment Operator ```js var a = 9; +var a = 9; +var b=10; +var myvar=0; ``` ## 5. Understanding Uninitialized Variables @@ -41,6 +44,10 @@ var a = 9; var a = 5; var b = 10; var c = "I am a"; + +var a=5; +var b=10; +var c="I am a"; ``` ## 6. Understanding Case Sensitivity in Variables ```js @@ -49,6 +56,16 @@ var studlyCapVar; var properCamelCase; var titleCaseOver; +// Assignments +studlyCapVar = 10; +properCamelCase = "A String"; +titleCaseOver = 9000; + +// Declarations +var studlyCapVar; +var properCamelCase; +var titleCaseOver; + // Assignments studlyCapVar = 10; properCamelCase = "A String"; @@ -59,17 +76,25 @@ titleCaseOver = 9000; ```js var sum = 10 + 0; sum = 10 + 10; + +var sum = 10 + 10; ``` ## 8. Subtract One Number from Another ```js +var difference = 45 - 33; + var difference = 45 - 33; ``` ## 9. Multiply Two Numbers ```js +var product = 8 * 10; + var product = 8 * 10; ``` ## 10. Divide One Number by Another (/) ```js +var quotient = 66 / 33; + var quotient = 66 / 33; ``` ## 11 .Increment a Number (i++) @@ -77,10 +102,15 @@ var quotient = 66 / 33; ```js var myVar = 87; myVar++; + +myVar++; +myVar=88 ``` ## 12. Decrement a Number (i--) ```js +myVar--; + myVar--; ``` @@ -88,27 +118,40 @@ myVar--; ## 13. Create Decimal Numbers ```js var myDecimal = 8.8; + +var myDecimal=9.873; ``` ## 14. Multiply Two Decimals ```js +var product = 2.0 * 2.5; + var product = 2.0 * 2.5; ``` ## 15. Divide One Decimal by Another ```js +var quotient = 4.4 / 2.0; + var quotient = 4.4 / 2.0; ``` ## 16. Finding a Remainder ```js var remainder; remainder = 11 % 3; + +remainder=11%3; +remainder=2; ``` ## 17. Compound Assignment With Augmented Addition (+=) ```js a += 12; b += 9; c += 7; + +a +=12; +b +=9; +c +=7; ``` ## 18. Compound Assignment With Augmented Subtraction (-=) @@ -116,18 +159,33 @@ c += 7; a -= 6; b -= 15; c -= 1; + +a -= 6; +b -=15; +c -= 1; ``` ## 19. Compound Assignment With Augmented Multiplication ```js a *= 5; b *= 3; c *= 10; + +a *= 5; +b *= 3; +c *=10; + + ``` ## 20. Compound Assignment With Augmented Division ```js a /= 12; b /= 4; c /= 11; + +a /= 12; +b /= 4; +c /= 11; + ``` ## 21. Declare String Variables @@ -135,6 +193,9 @@ with ``` " " ``` ```js var myFirstName = "Alfi"; var myLastName = "Yusrina"; + +var myFirstName="kelemu"; +var myLastName="Gebeyehu"; ``` ## 22. Escaping Literal Quotes in Strings From d3771d25fab2e615e1f64b7818b55f2d1c607328 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Sun, 23 Jun 2019 12:04:12 +0200 Subject: [PATCH 20/55] Update fcc-basic-js-pt-1.md --- week-1/fcc-basic-js-pt-1.md | 125 ++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/week-1/fcc-basic-js-pt-1.md b/week-1/fcc-basic-js-pt-1.md index 4d09b5f..1574479 100644 --- a/week-1/fcc-basic-js-pt-1.md +++ b/week-1/fcc-basic-js-pt-1.md @@ -202,6 +202,8 @@ var myLastName="Gebeyehu"; Using *backlash* ```\``` in the beginning and in the end of your quotes. ```js var myStr = "I am a \"double quoted\" string inside \"double quotes\"."; + +var myStr = "I am a \"double quoted\" string inside \"double quotes\"."; ``` ## 23. Quoting Strings with Single Quotes String values in JS may be written with single or double quotes. @@ -216,55 +218,94 @@ Reasons to use escaping characters: ```js var myStr = 'FirstLine\n\t\\SecondLine\nThirdLine'; + +var myStr='FirstLine\n\t\\SecondLine\nThirdLine'; // Change this line + +var myStr = 'Link'; ``` ## 25. Concatenating Strings with Plus Operator ```js var myStr = "This is the start. " + "This is the end."; + +var myStr="This is the start. "+"This is the end."; + +var myStr = "I am a \"double quoted\" string inside \"double quotes\"."; // Change this line ``` ## 26. Concatenating Strings with the Plus Equals Operator ```js var myStr = "This is the first sentence. "; myStr += "This is the second sentence."; + +var myStr = "This is the first sentence. "; +myStr += "This is the second sentence."; + ``` ## 27. Constructing Strings with Variables ```js var myStr = "My name is " + myName + " and I am well!"; + +var myName="kelemu"; +var myStr= "My name is " + myName + " and I am well!" ; ``` ## 28. Appending Variables to Strings ```js var someAdjective = "boring"; var myStr = "Learning to code is "; myStr += someAdjective; + +var someAdjective="Is it easy "; +var myStr = "Learning to code is "; +myStr += someAdjective; + ``` ## 29. Find the Length of a String ```js +lastNameLength = lastName.length; + lastNameLength = lastName.length; ``` ## 30. Use Bracket Notation to Find the First Character in a String ```js +firstLetterOfLastName = lastName[0]; + firstLetterOfLastName = lastName[0]; ``` ## 31. Understand String Immutability String values are *immutable*, means that they cannot be altered once created. ```js +myStr = "Hello World"; + + myStr = "Hello World"; ``` ## 32. Use Bracket Notation to Find the Nth Character in a String ```js +var thirdLetterOfLastName = lastName[2]; + var thirdLetterOfLastName = lastName[2]; ``` ## 33. Use Bracket Notation to Find the Last Character in a String Use ```.length-1``` ```js +var lastLetterOfLastName = lastName[lastName.length-1]; + var lastLetterOfLastName = lastName[lastName.length-1]; ``` ## 34. Use Bracket Notation to Find the Nth-to-Last Character in a String ```js var secondToLastLetterOfLastName = lastName[lastName.length - 2]; + +var secondToLastLetterOfLastName = lastName[lastName.length-2]; ``` ## 35. Word Blanks ```js +function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) { + var result = "The " + myAdjective + " " + myNoun + " " + myVerb + " " + myAdverb + "."; + return result; +} +wordBlanks("cat", "little", "hit", "slowly"); + function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) { var result = "The " + myAdjective + " " + myNoun + " " + myVerb + " " + myAdverb + "."; return result; @@ -275,33 +316,46 @@ wordBlanks("cat", "little", "hit", "slowly"); Array variables for storing several pieces of data in one place. ```js var myArray = ["Alfi", 28]; + +var myArray = ["kelemu",21]; ``` ## 37. Nest one Array within Another Array ```js var myArray = [["Bulls", 23], ["White Sox", 45]]; + +var myArray = [["computer",2019],['software,2018']]; ``` ## 39. Modify Array Data With Indexes ```js myArray[0] = 45; +var myData=myArray[0]; +myArray[0]=45; ``` ## 40. Access Multi-Dimensional Arrays With Indexes ```js +var myData = myArray[2][1]; + var myData = myArray[2][1]; ``` ## 41. Manipulate Arrays With push() Adding an extra to the last array. ```js myArray.push(["dog", 3]); + myArray.push(["dog", 3]); ``` ## 42. Manipulate Arrays With pop() You can pop off the last array, and store it in a variable. ```js var removedFromMyArray = myArray.pop(); + +var removedFromMyArray=myArray.pop(); ``` ## 43. Manipulate Arrays With shift() removing the first in the array ```js var removedFromMyArray = myArray.shift(); + +var removedFromMyArray=myArray.shift(); ``` ## 44. Manipulate Arrays With unshift() Adding an extra to the first in the array. @@ -310,10 +364,15 @@ var myArray = [["John", 23], ["dog", 3]]; myArray.shift(); myArray.unshift(["Paul",35]); + +myArray.unshift( ["Paul",35]) ``` ## 45. Shopping List ```js var myList = [["rice", 5] , ["bread", 6] , ["cake", 7], [ "quinoa", 9], ["potato", 20]]; + +var myList = [["bread",2],["rise",5],["oniown",5],["orange",10],["sope",3]]; + ``` ## 46. Write Reusable JavaScript with Functions ```js @@ -321,6 +380,12 @@ function reusableFunction() { console.log("Hi World"); } +reusableFunction(); + +unction reusableFunction(){ + console.log("Hi World"); +} + reusableFunction(); ``` ## 47. Passing Values to Functions with Arguments @@ -330,6 +395,11 @@ console.log(a + b); } functionWithArgs (1 , 2); functionWithArgs (7 , 9); + +function functionWithArgs(a,b){ + console.log(a+b); +} +functionWithArgs(5,9); ``` ## 48. Global Scope and Functions Scope refers to the visibility of variables. @@ -340,6 +410,26 @@ var myGlobal = 10; function fun1() { oopsGlobal = 5; } + +// Declare your variable here + var myGlobal=10; + +function fun1() { + // Assign 5 to oopsGlobal Here + oopsGlobal=5; +} + +// Only change code above this line +function fun2() { + var output = ""; + if (typeof myGlobal != "undefined") { + output += "myGlobal: " + myGlobal; + } + if (typeof oopsGlobal != "undefined") { + output += " oopsGlobal: " + oopsGlobal; + } + console.log(output); +} ``` ## 49. Local Scope and Functions ```js @@ -347,6 +437,14 @@ function myLocalScope() { var myVar = 'use strict'; } myLocalScope(); + +function myLocalScope() { + 'use strict'; // you shouldn't need to edit this line + var myVar; + console.log(myVar); + +} +myLocalScope(); ``` ## 50. Global vs. Local Scope in Functions ```js @@ -355,6 +453,20 @@ function myOutfit() { var outerWear = "sweater"; return outerWear; } +myOutfit(); + +// Setup +var outerWear = "T-Shirt"; + +function myOutfit() { + // Only change code below this line + var outerWear = "sweater"; + + + // Only change code above this line + return outerWear; +} + myOutfit(); ``` ## 51. Return a Value from a Function with Return @@ -366,12 +478,25 @@ function timesFive (num) { timesFive(5); timesFive(2); timesFive(0); + +function timesFive(mul){ + return mul * 5; +} + +console.log(timesFive(2)); ``` ## 52. Understanding Undefined Value returned from a Function ```js function addFive() { sum = sum + 5; } + +var sum=5; +function addFive(){ + sum=sum+5; +} + + ``` ## 53. Assignment with a Returned Value ```js From b7cf732cf0c3bf08afedfe505f01c5e97bdcf33b Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Mon, 24 Jun 2019 11:57:49 +0200 Subject: [PATCH 21/55] Update fcc-basic-js-pt-1.md --- week-1/fcc-basic-js-pt-1.md | 290 ++++++++++++++++++++++++++++++++++++ 1 file changed, 290 insertions(+) diff --git a/week-1/fcc-basic-js-pt-1.md b/week-1/fcc-basic-js-pt-1.md index 1574479..b825a67 100644 --- a/week-1/fcc-basic-js-pt-1.md +++ b/week-1/fcc-basic-js-pt-1.md @@ -518,12 +518,29 @@ function nextInLine(arr, item) { arr.push(item); return arr.shift(); } + +function nextInLine(arr, item) { + // Your code here + arr.push(item); + item= arr.shift(); + return item; // Change this line +} + +// Test Setup +var testArr = [1,2,3,4,5]; + +// Display Code +console.log("Before: " + JSON.stringify(testArr)); +console.log(nextInLine(testArr, 6)); // Modify this line to test +console.log("After: " + JSON.stringify(testArr)); ``` ## 55. Understanding Boolean Values ```js function welcomeToBooleans() { return true; } + +return true; // Change this line ``` ## 56. Use Conditional Logic with If Statements ```js @@ -534,6 +551,28 @@ function trueOrFalse(wasThatTrue) { return "No, that was false"; } trueOrFalse(true); + +function trueOrFalse(wasThatTrue) { + if(wasThatTrue){ + return "Yes, that was true"; + + } + return "No, that was false"; +} + +// Change this value to test +trueOrFalse(true); + +// Setup +function testEqual(val) { + if (val==12) { // Change this line + return "Equal"; + } + return "Not Equal"; +} + +// Change this value to test +testEqual(10); ``` ## 57. Comparison with the Equality Operator ```js @@ -544,6 +583,17 @@ function testEqual(val) { return "Not Equal"; } testEqual(12); + +// Setup +function testStrict(val) { + if (val===7) { // Change this line + return "Equal"; + } + return "Not Equal"; +} + +// Change this value to test +testStrict(10); ``` ## 58. Comparison with the Strict Equality Operator However, unlike the equality operator, which attempts to convert both values being compared to a common type, the strict equality operator does not perform a type conversion. @@ -557,6 +607,17 @@ function testStrict(val) { return "Not Equal"; } testStrict(10); + +// Setup +function compareEquality(a, b) { + if (a === "b") { // Change this line + return "Equal"; + } + return "Not Equal"; +} + +// Change this value to test +compareEquality(10, "10"); ``` ## 59. Practice comparing different values ```js @@ -577,6 +638,17 @@ function testNotEqual(val) { return "Equal"; } testNotEqual(10); + +// Setup +function testNotEqual(val) { + if (val != 99) { // Change this line + return "Not Equal"; + } + return "Equal"; +} + +// Change this value to test +testNotEqual(10); ``` ## 61. Comparison with the Strict Inequality Operator ```js @@ -587,6 +659,22 @@ function testStrictNotEqual(val) { return "Equal"; } +testStrictNotEqual(10); + +// Setup +function testStrictNotEqual(val) { + // Only Change Code Below this Line + + if (val !==17) { + + // Only Change Code Above this Line + + return "Not Equal"; + } + return "Equal"; +} + +// Change this value to test testStrictNotEqual(10); ``` ## 62. Comparison with the Greater Than Operator @@ -603,6 +691,21 @@ function testGreaterThan(val) { return "10 or Under"; } +testGreaterThan(10); + +function testGreaterThan(val) { + if (val > 100) { // Change this line + return "Over 100"; + } + + if (val> 10) { // Change this line + return "Over 10"; + } + + return "10 or Under"; +} + +// Change this value to test testGreaterThan(10); ``` ## 63. Comparison with the Greater Than Or Equal To Operator @@ -620,6 +723,21 @@ function testGreaterOrEqual(val) { } +testGreaterOrEqual(10); + +function testGreaterOrEqual(val) { + if (val>=20) { // Change this line + return "20 or Over"; + } + + if (val>=10) { // Change this line + return "10 or Over"; + } + + return "Less than 10"; +} + +// Change this value to test testGreaterOrEqual(10); ``` ## 64. Comparison with the Less Than Operator @@ -636,6 +754,21 @@ function testLessThan(val) { return "55 or Over"; } +testLessThan(10); + +function testLessThan(val) { + if (val < 25) { // Change this line + return "Under 25"; + } + + if (val< 55) { // Change this line + return "Under 55"; + } + + return "55 or Over"; +} + +// Change this value to test testLessThan(10); ``` ## 65. Comparison with the Less Than Or Equal To Operator @@ -654,6 +787,22 @@ function testLessOrEqual(val) { testLessOrEqual(10); +function testLessOrEqual(val) { + if (val <= 12) { // Change this line + return "Smaller Than or Equal to 12"; + } + + if (val <=24) { // Change this line + return "Smaller Than or Equal to 24"; + } + + return "More Than 24"; +} + +// Change this value to test +testLessOrEqual(10); + + ``` ## 66. Comparison with the Logical And Operator ```js @@ -667,6 +816,18 @@ function testLogicalAnd(val) { } +testLogicalAnd(10); + +function testLogicalAnd(val) { + + if (val >= 25 && val <= 50) { + return "Yes"; + } + + return "No"; +} + + testLogicalAnd(10); ``` ## 67. Comparison with the Logical Or Operator @@ -683,6 +844,20 @@ function testLogicalOr(val) { } +testLogicalOr(15); + +function testLogicalOr(val) { + // Only change code below this line + + if (val >20 || val <10) { + return "Outside"; + } + + // Only change code above this line + return "Inside"; +} + +// Change this value to test testLogicalOr(15); ``` ## 68. Introducing Else Statements @@ -706,6 +881,25 @@ function testElse(val) { testElse(4); +function testElse(val) { + var result = ""; + // Only change code below this line + + if (val > 5) { + result = "Bigger than 5"; + } + +else { + result = "5 or Smaller"; + } + + // Only change code above this line + return result; +} + +// Change this value to test +testElse(4); + ``` ## 69. Introducing Else If Statements ```js @@ -725,6 +919,23 @@ function testElseIf(val) { testElseIf(7); +function testElseIf(val) { + if (val > 10) { + return "Greater than 10"; + } + + else if (val < 5) { + return "Smaller than 5"; + } + else{ + return "Between 5 and 10"; + } +} + +// Change this value to test +testElseIf(7); + + ``` ## 70. Logical Order in If Else Statements ```js @@ -738,6 +949,19 @@ function orderMyLogic(val) { } } +orderMyLogic(7); + +function orderMyLogic(val) { + if (val < 5) { + return "Less than 5"; + } else if (val < 10) { + return "Less than 10"; + } else { + return "Greater than or equal to 10"; + } +} + +// Change this value to test orderMyLogic(7); ``` ## 71. Chaining If Else Statements @@ -758,6 +982,36 @@ return "Large"; } +testSize(7); + +function testSize(num) { + // Only change code below this line + if(num<5){ + return "Tiny" + } + + else if(num<10){ + return "Small" + } + + else if (num<15){ + return "Medium" + } + + else if (num<20){ + return "Large" + } + + else if (num>= 20){ + return "Huge" + } + else{ + return "Change Me"; + } + // Only change code above this line +} + +// Change this value to test testSize(7); ``` ## 72. Golf Code @@ -783,6 +1037,42 @@ return "Hole-in-one!"; } } +golfScore(5, 4); + +var names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"]; +function golfScore(par, strokes) { + // Only change code below this line + if (strokes == 1){ + return names[0]; + } + else if (strokes<= par-2){ + return names[1]; + } + + else if (strokes<= par-1){ + return names[2]; + } + + else if (strokes<= par){ + return names[3]; + } + + else if (strokes<= par+1){ + return names[4]; + } + + else if (strokes<= par+2){ + return names[5]; + } + + else { + return names[6]; + } + + // Only change code above this line +} + +// Change these values to test golfScore(5, 4); ``` From d4364158aa31ed22f023e6c5ecfa7a2c880ea9f0 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Mon, 24 Jun 2019 12:00:00 +0200 Subject: [PATCH 22/55] Update README.md --- week-1/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-1/README.md b/week-1/README.md index c1da9ec..b71e2ad 100644 --- a/week-1/README.md +++ b/week-1/README.md @@ -2,7 +2,7 @@ | | your Emoji | your comments | coach emoji | coach comments | | --- | --- | --- | --- | --- | -| :seedling: __[fcc basics](./fcc-basic-js-pt-1.md)__: through ```Counting Cards``` |:wavy_dash: | | | | +| :seedling: __[fcc basics](./fcc-basic-js-pt-1.md)__: through ```Counting Cards``` | :white_check_mark: | it need a lot practice | | | | :dash: __[fcc debugging](./fcc-debugging.md)__ | | | | | | :seedling: __[errors: formatting](./jl-errors-formatting.md)__ | | | | | | :seedling: __[errors: primitives](./jl-errors-primitive-types.md)__ | | | | | From 6b03b14219d0c6b5e6b33fcacfb678f59ed9168a Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Mon, 24 Jun 2019 20:48:13 +0200 Subject: [PATCH 23/55] Update jl-errors-formatting.md --- week-1/jl-errors-formatting.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/week-1/jl-errors-formatting.md b/week-1/jl-errors-formatting.md index 32fe50f..3266400 100644 --- a/week-1/jl-errors-formatting.md +++ b/week-1/jl-errors-formatting.md @@ -19,12 +19,16 @@ let a = 1: error message: ``` Uncaught SyntaxError: Unexpected token : +SyntaxError: unexpected token: ':' ``` classification: * creation phase or execution phase ? * syntax or semanitc ? +It is creation phase and +syntax the fix: +let a= 1; ```js ``` your notes: From 4da49d291ff428b3fded65af77da610e5dcb9917 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Mon, 24 Jun 2019 22:26:09 +0200 Subject: [PATCH 24/55] Update jl-errors-primitive-types.md --- week-1/jl-errors-primitive-types.md | 81 ++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/week-1/jl-errors-primitive-types.md b/week-1/jl-errors-primitive-types.md index 4182409..63c8816 100644 --- a/week-1/jl-errors-primitive-types.md +++ b/week-1/jl-errors-primitive-types.md @@ -1,3 +1,82 @@ > paste [this markdown](https://raw.githubusercontent.com/janke-learning/errors/master/primitive-types.md) into this file and fix the errors! > [completed example](https://github.com/AlfiYusrina/hyf-javascript1/blob/master/week1/errors_solutions.MD) (of the old version) -> references: [errors & life-cycle](https://github.com/janke-learning/errors-and-life-cycle), [exercise repo](https://github.com/janke-learning/errors) \ No newline at end of file +> references: [errors & life-cycle](https://github.com/janke-learning/errors-and-life-cycle), [exercise repo](https://github.com/janke-learning/errors) + +# Primitive Type Errors + +* [improper multi-line string](#improper-multi-line-string) +* [improper nested quotes 1](#improper-nested-quotes-1) +* [improper nested quotes 2](#improper-nested-quotes-2) + +--- + +## improper multi-line string + +broken code: +```js +let a = 'this is +two lines'; +``` +error message: +``` +``` +classification: +* creation phase or execution phase ? +* syntax or semanitc ? + +the fix: +```js +``` +your notes: + +[TOP](#primitive-type-errors) + +--- + +## improper nested quotes 1 + +broken code: +```js +let innerHtml = "

Click here to return home

"; +``` +error message: +``` +``` +classification: +* creation phase or execution phase ? +* syntax or semanitc ? + +the fix: +```js +``` +your notes: + +[TOP](#errors) + +--- + +## improper nested quotes 2 + +broken code: +```js +let nested_messages = 'remind yourself ''i can do this!'' at least once a day'; +``` +error message: +``` +``` +classification: +* creation phase or execution phase ? +* syntax or semanitc ? + +the fix: +```js +``` +your notes: + +[TOP](#primitive-type-errors) + +___ +___ +### Janke Learning + + From 2aca92cd3c325c4637fdca94540886bbe96682ae Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Mon, 24 Jun 2019 22:29:58 +0200 Subject: [PATCH 25/55] Update jl-errors-primitive-types.md --- week-1/jl-errors-primitive-types.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/week-1/jl-errors-primitive-types.md b/week-1/jl-errors-primitive-types.md index 63c8816..a7a0974 100644 --- a/week-1/jl-errors-primitive-types.md +++ b/week-1/jl-errors-primitive-types.md @@ -19,13 +19,17 @@ two lines'; ``` error message: ``` +SyntaxError: '' string literal contains an unescaped line break ``` classification: * creation phase or execution phase ? * syntax or semanitc ? +* +creation phase and Synatx the fix: ```js +let a = 'this is \"two lines\"'; ``` your notes: From abc70f1a808343c85bc4c330db49f42d14bec86b Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Mon, 24 Jun 2019 22:40:27 +0200 Subject: [PATCH 26/55] Update jl-errors-primitive-types.md --- week-1/jl-errors-primitive-types.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/week-1/jl-errors-primitive-types.md b/week-1/jl-errors-primitive-types.md index a7a0974..a60da7b 100644 --- a/week-1/jl-errors-primitive-types.md +++ b/week-1/jl-errors-primitive-types.md @@ -23,9 +23,9 @@ SyntaxError: '' string literal contains an unescaped line break ``` classification: * creation phase or execution phase ? + * syntax or semanitc ? -* creation phase and Synatx the fix: ```js @@ -45,16 +45,19 @@ let innerHtml = "

Click here to return home

"; ``` error message: ``` +SyntaxError: fields are not currently supported ``` classification: * creation phase or execution phase ? * syntax or semanitc ? +creation and syntax the fix: ```js +let innerHtml = '

"Click here to" return home

'; ``` your notes: - + improper uses of single and double quet [TOP](#errors) --- @@ -67,16 +70,19 @@ let nested_messages = 'remind yourself ''i can do this!'' at least once a day'; ``` error message: ``` + unexpected token: string literal ``` classification: * creation phase or execution phase ? * syntax or semanitc ? +* the fix: ```js +let nested_messages = "remind yourself '\i can do this!'\ at least once a day"; ``` your notes: - +Misplaced used of single and double quets [TOP](#primitive-type-errors) ___ From 073d649bd1a86395f012422cbbf632ddf6dad678 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Mon, 24 Jun 2019 22:42:45 +0200 Subject: [PATCH 27/55] Update README.md --- week-1/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/week-1/README.md b/week-1/README.md index b71e2ad..e5f916b 100644 --- a/week-1/README.md +++ b/week-1/README.md @@ -4,8 +4,8 @@ | --- | --- | --- | --- | --- | | :seedling: __[fcc basics](./fcc-basic-js-pt-1.md)__: through ```Counting Cards``` | :white_check_mark: | it need a lot practice | | | | :dash: __[fcc debugging](./fcc-debugging.md)__ | | | | | -| :seedling: __[errors: formatting](./jl-errors-formatting.md)__ | | | | | -| :seedling: __[errors: primitives](./jl-errors-primitive-types.md)__ | | | | | +| :seedling: __[errors: formatting](./jl-errors-formatting.md)__ | :white_check_mark:| | | | +| :seedling: __[errors: primitives](./jl-errors-primitive-types.md)__ | :white_check_mark:| | | | | :seedling: __[errors: variables](./jl-errors-variables.md)__ | | | | | | :seedling: __[varibales: swaps](./jl-variables-swaps.md)__ | | | | | | :dash: __[variables: multiple assignments](./jl-variables-multiple.md)__ | | | | | From e43b642ccf72fc3fd2228ef0a5be2524683d6da3 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Mon, 24 Jun 2019 23:50:12 +0200 Subject: [PATCH 28/55] Update jl-errors-variables.md --- week-1/jl-errors-variables.md | 75 ++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/week-1/jl-errors-variables.md b/week-1/jl-errors-variables.md index ce210bd..c906cd2 100644 --- a/week-1/jl-errors-variables.md +++ b/week-1/jl-errors-variables.md @@ -1,3 +1,76 @@ > paste [this markdown](https://raw.githubusercontent.com/janke-learning/errors/master/functions.md) into this file and fix the errors! > [completed example](https://github.com/AlfiYusrina/hyf-javascript1/blob/master/week1/errors_solutions.MD) (of the old version) -> references: [errors & life-cycle](https://github.com/janke-learning/errors-and-life-cycle), [exercise repo](https://github.com/janke-learning/errors) \ No newline at end of file +> references: [errors & life-cycle](https://github.com/janke-learning/errors-and-life-cycle), [exercise repo](https://github.com/janke-learning/errors) + +# Function Errors + +* [missing arguments](#missing-arguments) +* [is not a function](#is-not-a-function) + +--- + +## missing arguments + +broken code: +```js +function getNine { + let x = 6; + let y = 3; + return x + y; +} +let result = getNine(); +``` +error message: +``` +SyntaxError: missing ( before formal parameters +``` +classification: +* creation phase or execution phase ? +* syntax or semanitc ? + +syntax and creation +the fix: +```js +function getNine() { + let x = 6; + let y = 3; + return x + y; +} +let result = getNine(); +``` +your notes: + +[TOP](#function-errors) +Mising Parentecise (improper function decleration) +--- + +## is not a function + +broken code: +```js +let array = []; +array.length() +``` +error message: +``` +redeclaration of let array +``` +classification: +* creation phase or execution phase ? +* syntax or semanitc ? +creation phase annd semanitc +the fix: +```js +let xy = []; +xy.length; +``` +your notes: + +using the array as a function + +[TOP](#function-errors) + + +___ +___ +### Janke Learning From 15193a0363bbbe4c744acc8c141b62f13a71168a Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Tue, 25 Jun 2019 16:16:47 +0200 Subject: [PATCH 29/55] Update jl-errors-variables.md --- week-1/jl-errors-variables.md | 61 +++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/week-1/jl-errors-variables.md b/week-1/jl-errors-variables.md index c906cd2..a46987e 100644 --- a/week-1/jl-errors-variables.md +++ b/week-1/jl-errors-variables.md @@ -70,6 +70,67 @@ using the array as a function [TOP](#function-errors) +# Function Errors + +* [missing arguments](#missing-arguments) +* [is not a function](#is-not-a-function) + +--- + +## missing arguments + +broken code: +```js +function getNine { + let x = 6; + let y = 3; + return x + y; +} +let result = getNine(); +``` +error message: +``` +``` +classification: +* creation phase or execution phase ? +* syntax or semanitc ? + +the fix: +```js +``` +your notes: + +[TOP](#function-errors) + +--- + +## is not a function + +broken code: +```js +let array = []; +array.length() +``` +error message: +``` +``` +classification: +* creation phase or execution phase ? +* syntax or semanitc ? + +the fix: +```js +``` +your notes: + + + +[TOP](#function-errors) + + +___ +___ +### Janke Learning ___ ___ From b386ce8c4dac106ed229cf979a611f70083056f6 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Tue, 25 Jun 2019 16:21:15 +0200 Subject: [PATCH 30/55] Update jl-errors-variables.md --- week-1/jl-errors-variables.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-1/jl-errors-variables.md b/week-1/jl-errors-variables.md index a46987e..6c24261 100644 --- a/week-1/jl-errors-variables.md +++ b/week-1/jl-errors-variables.md @@ -39,7 +39,7 @@ function getNine() { let result = getNine(); ``` your notes: - +Function declered without parentacies [TOP](#function-errors) Mising Parentecise (improper function decleration) --- From e2342daf048673dbfb28100f81feb0edcfaff500 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Tue, 25 Jun 2019 16:22:16 +0200 Subject: [PATCH 31/55] Update jl-errors-variables.md --- week-1/jl-errors-variables.md | 55 ----------------------------------- 1 file changed, 55 deletions(-) diff --git a/week-1/jl-errors-variables.md b/week-1/jl-errors-variables.md index 6c24261..dd7218a 100644 --- a/week-1/jl-errors-variables.md +++ b/week-1/jl-errors-variables.md @@ -77,61 +77,6 @@ using the array as a function --- -## missing arguments - -broken code: -```js -function getNine { - let x = 6; - let y = 3; - return x + y; -} -let result = getNine(); -``` -error message: -``` -``` -classification: -* creation phase or execution phase ? -* syntax or semanitc ? - -the fix: -```js -``` -your notes: - -[TOP](#function-errors) - ---- - -## is not a function - -broken code: -```js -let array = []; -array.length() -``` -error message: -``` -``` -classification: -* creation phase or execution phase ? -* syntax or semanitc ? - -the fix: -```js -``` -your notes: - - - -[TOP](#function-errors) - - -___ -___ -### Janke Learning - ___ ___ ### Janke Learning From 7504ca6ef8ee6da85450be2fab2e5d1a4955876e Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Tue, 25 Jun 2019 16:22:53 +0200 Subject: [PATCH 32/55] Update jl-errors-variables.md --- week-1/jl-errors-variables.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/week-1/jl-errors-variables.md b/week-1/jl-errors-variables.md index dd7218a..11481de 100644 --- a/week-1/jl-errors-variables.md +++ b/week-1/jl-errors-variables.md @@ -38,8 +38,8 @@ function getNine() { } let result = getNine(); ``` -your notes: -Function declered without parentacies +your notes: Function declered without parentacies + [TOP](#function-errors) Mising Parentecise (improper function decleration) --- From 13a1b94110006e9098ec416069a0eca85012a6a8 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Tue, 25 Jun 2019 16:23:49 +0200 Subject: [PATCH 33/55] Update jl-errors-variables.md --- week-1/jl-errors-variables.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-1/jl-errors-variables.md b/week-1/jl-errors-variables.md index 11481de..7dced89 100644 --- a/week-1/jl-errors-variables.md +++ b/week-1/jl-errors-variables.md @@ -41,7 +41,7 @@ let result = getNine(); your notes: Function declered without parentacies [TOP](#function-errors) -Mising Parentecise (improper function decleration) + --- ## is not a function From 15fd4dfd5cd01712e82cd548d253e4099387d5f8 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Tue, 25 Jun 2019 16:24:50 +0200 Subject: [PATCH 34/55] Update README.md --- week-1/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-1/README.md b/week-1/README.md index e5f916b..b573dbb 100644 --- a/week-1/README.md +++ b/week-1/README.md @@ -6,7 +6,7 @@ | :dash: __[fcc debugging](./fcc-debugging.md)__ | | | | | | :seedling: __[errors: formatting](./jl-errors-formatting.md)__ | :white_check_mark:| | | | | :seedling: __[errors: primitives](./jl-errors-primitive-types.md)__ | :white_check_mark:| | | | -| :seedling: __[errors: variables](./jl-errors-variables.md)__ | | | | | +| :seedling: __[errors: variables](./jl-errors-variables.md)__ | :white_check_mark:| | | | | :seedling: __[varibales: swaps](./jl-variables-swaps.md)__ | | | | | | :dash: __[variables: multiple assignments](./jl-variables-multiple.md)__ | | | | | | :seedling: __[how functions work](./jl-functions.md)__ | | | | | From 23ea215b6a3f0f81ec6541ab2a60968acc9dfd75 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Tue, 25 Jun 2019 17:13:29 +0200 Subject: [PATCH 35/55] Update jl-variables-swaps.md --- week-1/jl-variables-swaps.md | 60 ++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/week-1/jl-variables-swaps.md b/week-1/jl-variables-swaps.md index d5a8279..cfe04f4 100644 --- a/week-1/jl-variables-swaps.md +++ b/week-1/jl-variables-swaps.md @@ -36,4 +36,64 @@ You'll be given a bunch of variables with the wrong value assigned and a tempora ___ ___ +# Multiple Assignments + +There are mechanisms for assigning multiple variables on one line: +* _chaining assignments_ - ```a = b = c = 4;``` +* _comma-separated assignments_ - ```a = 1, b = 2, c = 3;``` + +These exercises will help you practice multiple assignments on one line: +1. [chaining assignments](#chaining-assignments) +1. [comma-separated assignments](#comma-separated-assignments) + +--- + +## Chaining Assignments + +### completed examples +* the first: [pytut](http://www.pythontutor.com/javascript.html#code=var%20a%20%3D%20'b'%3B%0Avar%20b1%20%3D%20'a',%20b2%20%3D%20'a'%3B%0Avar%20_%20%3D%20''%3B%0A%0A_%20%3D%20b1%3B%0Ab1%20%3D%20b2%20%3D%20a%3B%0Aa%20%3D%20_%3B&curInstr=0&mode=display&origin=opt-frontend.js&py=js&rawInputLstJSON=%5B%5D), [parsonized](https://janke-learning.github.io/parsonizer/?snippet=var%20a%20%3D%20'b'%3B%0Avar%20b1%20%3D%20'a'%2C%20b2%20%3D%20'a'%3B%0Avar%20_%20%3D%20''%3B%0A%0A_%20%3D%20b1%3B%0Ab1%20%3D%20b2%20%3D%20a%3B%0Aa%20%3D%20_%3B) +* the second: [pytut](http://www.pythontutor.com/javascript.html#code=var%20a%20%3D%20'c'%3B%0Avar%20b1%20%3D%20'a',%20b2%20%3D%20'a'%3B%0Avar%20c1%20%3D%20'b',%20c2%20%3D%20'b',%20c3%3B%0Ac3%20%3D%20'b'%3B%0Avar%20_%20%3D%20''%3B%0A%0A_%20%3D%20a%3B%0Aa%20%3D%20b1%3B%0Ab1%20%3D%20b2%20%3D%20c1%3B%0Ac1%20%3D%20c2%20%3D%20c3%20%3D%20_%3B&curInstr=0&mode=display&origin=opt-frontend.js&py=js&rawInputLstJSON=%5B%5D), +[parsonized](https://janke-learning.github.io/parsonizer/?snippet=var%20a%20%3D%20'c'%3B%0Avar%20b1%20%3D%20'a'%2C%20b2%20%3D%20'a'%3B%0Avar%20c1%20%3D%20'b'%2C%20c2%20%3D%20'b'%2C%20c3%3B%0Ac3%20%3D%20'b'%3B%0Avar%20_%20%3D%20''%3B%0A%0A_%20%3D%20a%3B%0Aa%20%3D%20b1%3B%0Ab1%20%3D%20b2%20%3D%20c1%3B%0Ac1%20%3D%20c2%20%3D%20c3%20%3D%20_%3B) + +### exercises +* [the first](http://www.pythontutor.com/live.html#code=var%20a%20%3D%20'b'%3B%0Avar%20b1%20%3D%20'a',%20b2%20%3D%20'a'%3B%0Avar%20_%20%3D%20''%3B%0A%0A//%20--%20can%20be%20done%20in%203%20lines&cumulative=false&curInstr=3&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) +```js +// your solution here +``` +* [the second](http://www.pythontutor.com/live.html#code=var%20a%20%3D%20'c'%3B%0Avar%20b1%20%3D%20'a',%20b2%20%3D%20'a'%3B%0Avar%20c1%20%3D%20'b',%20c2,%20c3%3B%0Ac2%20%3D%20'b',%20c3%20%3D%20'b'%3B%0Avar%20_%20%3D%20''%3B%0A%0A//%20---%20can%20be%20done%20in%204%20lines%20---&cumulative=false&curInstr=5&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) +```js +// your solution here +``` + +[TOP](#multiple-assignments) + +--- + +## Comma-Separated Assignments + +### completed examples +* basic swap: [pytut](http://www.pythontutor.com/javascript.html#code=var%20a%20%3D%20'b',%20b%20%3D%20'a'%3B%0Avar%20_%20%3D%20''%3B%0A%0A_%20%3D%20a,%20a%20%3D%20b,%20b%20%3D%20_%3B&curInstr=0&mode=display&origin=opt-frontend.js&py=js&rawInputLstJSON=%5B%5D), [parsonized](https://janke-learning.github.io/parsonizer/?snippet=var%20a%20%3D%20'b'%2C%20b%20%3D%20'a'%3B%0Avar%20_%20%3D%20''%3B%0A%0A_%20%3D%20a%2C%20a%20%3D%20b%2C%20b%20%3D%20_%3B) +* double swap - two lines: [pytut](http://www.pythontutor.com/javascript.html#code=var%20a,%20b,%20c%3B%0Aa%20%3D%20'b',%20b%20%3D%20'c',%20c%20%3D%20'a'%3B%0Avar%20_%20%3D%20''%3B%0A%0A_%20%3D%20a,%20a%20%3D%20c%3B%0Ac%20%3D%20b,%20b%20%3D%20_%3B&curInstr=0&mode=display&origin=opt-frontend.js&py=js&rawInputLstJSON=%5B%5D), [parsonized](https://janke-learning.github.io/parsonizer/?snippet=var%20a%2C%20b%2C%20c%3B%0Aa%20%3D%20'b'%2C%20b%20%3D%20'c'%2C%20c%20%3D%20'a'%3B%0Avar%20_%20%3D%20''%3B%0A%0A_%20%3D%20a%2C%20a%20%3D%20c%3B%0Ac%20%3D%20b%2C%20b%20%3D%20_%3B) +* double swap - one line: [pytut](http://www.pythontutor.com/javascript.html#code=var%20a,%20b%20%3D%20'c',%20c%20%3D%20'a'%3B%0Aa%20%3D%20'b'%3B%0Avar%20_%20%3D%20''%3B%0A%0A_%20%3D%20a,%20a%20%3D%20c,%20c%20%3D%20b,%20b%20%3D%20_%3B&curInstr=0&mode=display&origin=opt-frontend.js&py=js&rawInputLstJSON=%5B%5D), [parsonized](https://janke-learning.github.io/parsonizer/?snippet=var%20a%2C%20b%20%3D%20'c'%2C%20c%20%3D%20'a'%3B%0Aa%20%3D%20'b'%3B%0Avar%20_%20%3D%20''%3B%0A%0A_%20%3D%20a%2C%20a%20%3D%20c%2C%20c%20%3D%20b%2C%20b%20%3D%20_%3B) + +### exercises +* [basic swap](http://www.pythontutor.com/live.html#code=var%20a%20%3D%20'b',%20b%20%3D%20'a'%3B%0Avar%20_%20%3D%20''%3B%0A%0A//%20---%20solve%20this%20in%20one%20line%20---&cumulative=false&curInstr=2&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) +```js +// your solution here +``` +* [double swap - two lines](http://www.pythontutor.com/live.html#code=var%20a,%20b,%20c%3B%0Aa%20%3D%20'b',%20b%20%3D%20'c',%20c%20%3D%20'a'%3B%0Avar%20_%20%3D%20''%3B%0A%0A//%20---%20solve%20this%20in%202%20lines%20---&cumulative=false&curInstr=3&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) +```js +// your solution here +``` +* [double swap - one line](http://www.pythontutor.com/live.html#code=var%20a%20%3D%20'b',%20b%20%3D%20'c',%20c%20%3D%20'a'%3B%0Avar%20_%20%3D%20''%3B%0A%0A_%20%3D%20a,%20a%20%3D%20c,%20c%20%3D%20b,%20b%20%3D%20_%3B&cumulative=false&curInstr=3&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) +```js +// your solution here +``` + +[TOP](#multiple-assignments) + +___ +___ +### Janke Learning + ### Janke Learning From 01156fd6044c6c484931d4e7babc8186b2adb202 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Tue, 25 Jun 2019 17:18:55 +0200 Subject: [PATCH 36/55] Update jl-variables-swaps.md --- week-1/jl-variables-swaps.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/week-1/jl-variables-swaps.md b/week-1/jl-variables-swaps.md index cfe04f4..44f4f1e 100644 --- a/week-1/jl-variables-swaps.md +++ b/week-1/jl-variables-swaps.md @@ -16,6 +16,9 @@ You'll be given a bunch of variables with the wrong value assigned and a tempora 1. [the first](https://goo.gl/k9jdZy) ```js // your solution here + _=a; +6 a=b; +7 b=_; ``` 1. [the second](https://goo.gl/KvayUU) ```js From cf28de18dad5eec914c79257cc978987667f0650 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Tue, 25 Jun 2019 17:25:17 +0200 Subject: [PATCH 37/55] Update jl-variables-swaps.md --- week-1/jl-variables-swaps.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/week-1/jl-variables-swaps.md b/week-1/jl-variables-swaps.md index 44f4f1e..853e6ee 100644 --- a/week-1/jl-variables-swaps.md +++ b/week-1/jl-variables-swaps.md @@ -23,6 +23,11 @@ You'll be given a bunch of variables with the wrong value assigned and a tempora 1. [the second](https://goo.gl/KvayUU) ```js // your solution here +_=a; +6 a=b; +7 b=c; +8 c=d; +9 d=_; ``` 1. [the third](https://goo.gl/WXXtV7) ```js From b9f0adaf39187f61b1ea62d4e81e233a1f916da6 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Tue, 25 Jun 2019 17:36:07 +0200 Subject: [PATCH 38/55] Update jl-variables-swaps.md --- week-1/jl-variables-swaps.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/week-1/jl-variables-swaps.md b/week-1/jl-variables-swaps.md index 853e6ee..0f91192 100644 --- a/week-1/jl-variables-swaps.md +++ b/week-1/jl-variables-swaps.md @@ -32,10 +32,19 @@ _=a; 1. [the third](https://goo.gl/WXXtV7) ```js // your solution here +7 a=b; +8 b=c; +9 c=d; +10 d=_; ``` 1. [the fourth](https://goo.gl/nTA1DG) ```js // your solution here +7 a=d; +8 d=b; +9 b=c; +10 c=d; +11 d=_ ``` 1. [the fifth](https://goo.gl/gDaKNi) ```js From e170fce59b8d54fe78f3642fc5bb3ced59b390e0 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Tue, 25 Jun 2019 17:43:55 +0200 Subject: [PATCH 39/55] Update jl-variables-swaps.md --- week-1/jl-variables-swaps.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/week-1/jl-variables-swaps.md b/week-1/jl-variables-swaps.md index 0f91192..ebf6911 100644 --- a/week-1/jl-variables-swaps.md +++ b/week-1/jl-variables-swaps.md @@ -49,6 +49,12 @@ _=a; 1. [the fifth](https://goo.gl/gDaKNi) ```js // your solution here + _ = a; +7 a = e; +8 e = b; +9 b= d; +10 d =e; +11 e = _; ``` ___ From e3a744848744bba1740df1eca6a4b68e58a70aee Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Tue, 25 Jun 2019 21:26:00 +0200 Subject: [PATCH 40/55] Update jl-variables-swaps.md --- week-1/jl-variables-swaps.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/week-1/jl-variables-swaps.md b/week-1/jl-variables-swaps.md index ebf6911..f2255c2 100644 --- a/week-1/jl-variables-swaps.md +++ b/week-1/jl-variables-swaps.md @@ -81,7 +81,10 @@ These exercises will help you practice multiple assignments on one line: ### exercises * [the first](http://www.pythontutor.com/live.html#code=var%20a%20%3D%20'b'%3B%0Avar%20b1%20%3D%20'a',%20b2%20%3D%20'a'%3B%0Avar%20_%20%3D%20''%3B%0A%0A//%20--%20can%20be%20done%20in%203%20lines&cumulative=false&curInstr=3&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) ```js -// your solution here +// your solution here_ = a; +a=b1; +b1=b2= _; + ``` * [the second](http://www.pythontutor.com/live.html#code=var%20a%20%3D%20'c'%3B%0Avar%20b1%20%3D%20'a',%20b2%20%3D%20'a'%3B%0Avar%20c1%20%3D%20'b',%20c2,%20c3%3B%0Ac2%20%3D%20'b',%20c3%20%3D%20'b'%3B%0Avar%20_%20%3D%20''%3B%0A%0A//%20---%20can%20be%20done%20in%204%20lines%20---&cumulative=false&curInstr=5&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) ```js From b4892c86f795965b0aa9934932841f3f0c91f340 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Tue, 25 Jun 2019 21:30:49 +0200 Subject: [PATCH 41/55] Update jl-variables-swaps.md --- week-1/jl-variables-swaps.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/week-1/jl-variables-swaps.md b/week-1/jl-variables-swaps.md index f2255c2..4289c13 100644 --- a/week-1/jl-variables-swaps.md +++ b/week-1/jl-variables-swaps.md @@ -89,6 +89,10 @@ b1=b2= _; * [the second](http://www.pythontutor.com/live.html#code=var%20a%20%3D%20'c'%3B%0Avar%20b1%20%3D%20'a',%20b2%20%3D%20'a'%3B%0Avar%20c1%20%3D%20'b',%20c2,%20c3%3B%0Ac2%20%3D%20'b',%20c3%20%3D%20'b'%3B%0Avar%20_%20%3D%20''%3B%0A%0A//%20---%20can%20be%20done%20in%204%20lines%20---&cumulative=false&curInstr=5&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) ```js // your solution here +_ =a; +a=b1; +b1=b2= c1; +c1=c2=c3=_; ``` [TOP](#multiple-assignments) From 7db34df5b5362521af11c3fdba5c8aa6427876a8 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Tue, 25 Jun 2019 21:46:46 +0200 Subject: [PATCH 42/55] Update jl-variables-swaps.md --- week-1/jl-variables-swaps.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/week-1/jl-variables-swaps.md b/week-1/jl-variables-swaps.md index 4289c13..6ee7129 100644 --- a/week-1/jl-variables-swaps.md +++ b/week-1/jl-variables-swaps.md @@ -110,10 +110,13 @@ c1=c2=c3=_; * [basic swap](http://www.pythontutor.com/live.html#code=var%20a%20%3D%20'b',%20b%20%3D%20'a'%3B%0Avar%20_%20%3D%20''%3B%0A%0A//%20---%20solve%20this%20in%20one%20line%20---&cumulative=false&curInstr=2&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) ```js // your solution here +_= a, a=b,b=_; ``` * [double swap - two lines](http://www.pythontutor.com/live.html#code=var%20a,%20b,%20c%3B%0Aa%20%3D%20'b',%20b%20%3D%20'c',%20c%20%3D%20'a'%3B%0Avar%20_%20%3D%20''%3B%0A%0A//%20---%20solve%20this%20in%202%20lines%20---&cumulative=false&curInstr=3&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) ```js // your solution here +_=a, a = c; +c=b,b=_; ``` * [double swap - one line](http://www.pythontutor.com/live.html#code=var%20a%20%3D%20'b',%20b%20%3D%20'c',%20c%20%3D%20'a'%3B%0Avar%20_%20%3D%20''%3B%0A%0A_%20%3D%20a,%20a%20%3D%20c,%20c%20%3D%20b,%20b%20%3D%20_%3B&cumulative=false&curInstr=3&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) ```js From c5cd5c31fb27cd3470beef8693ca7c547da4c2b2 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Tue, 25 Jun 2019 21:49:44 +0200 Subject: [PATCH 43/55] Update jl-variables-swaps.md --- week-1/jl-variables-swaps.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/week-1/jl-variables-swaps.md b/week-1/jl-variables-swaps.md index 6ee7129..0025369 100644 --- a/week-1/jl-variables-swaps.md +++ b/week-1/jl-variables-swaps.md @@ -121,6 +121,8 @@ c=b,b=_; * [double swap - one line](http://www.pythontutor.com/live.html#code=var%20a%20%3D%20'b',%20b%20%3D%20'c',%20c%20%3D%20'a'%3B%0Avar%20_%20%3D%20''%3B%0A%0A_%20%3D%20a,%20a%20%3D%20c,%20c%20%3D%20b,%20b%20%3D%20_%3B&cumulative=false&curInstr=3&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) ```js // your solution here + +_ = a, a = c, c = b, b = _; ``` [TOP](#multiple-assignments) @@ -129,4 +131,4 @@ ___ ___ ### Janke Learning -### Janke Learning + From c34ee3057ea39ec09bccffd0e8d2cd2c83898551 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Tue, 25 Jun 2019 21:50:39 +0200 Subject: [PATCH 44/55] Update README.md --- week-1/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-1/README.md b/week-1/README.md index b573dbb..c6eb99b 100644 --- a/week-1/README.md +++ b/week-1/README.md @@ -7,7 +7,7 @@ | :seedling: __[errors: formatting](./jl-errors-formatting.md)__ | :white_check_mark:| | | | | :seedling: __[errors: primitives](./jl-errors-primitive-types.md)__ | :white_check_mark:| | | | | :seedling: __[errors: variables](./jl-errors-variables.md)__ | :white_check_mark:| | | | -| :seedling: __[varibales: swaps](./jl-variables-swaps.md)__ | | | | | +| :seedling: __[varibales: swaps](./jl-variables-swaps.md)__ | :white_check_mark:| | | | | :dash: __[variables: multiple assignments](./jl-variables-multiple.md)__ | | | | | | :seedling: __[how functions work](./jl-functions.md)__ | | | | | | :dash: __[functions: turtle shuffle](./jl-turtle-shuffle.md)__ | | | | | From 9153d258e7d70dcffc26a1af387b272684896ac0 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Tue, 25 Jun 2019 23:08:59 +0200 Subject: [PATCH 45/55] Update jl-functions.md --- week-1/jl-functions.md | 222 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 221 insertions(+), 1 deletion(-) diff --git a/week-1/jl-functions.md b/week-1/jl-functions.md index d24d0e7..be00e79 100644 --- a/week-1/jl-functions.md +++ b/week-1/jl-functions.md @@ -1,2 +1,222 @@ > paste [this markdown of exercises](https://raw.githubusercontent.com/janke-learning/function-exercises/master/functions.md) into this file and complete the exercises! -> references: [javascript.info functions](https://javascript.info/function-basics), [function examples to study](https://github.com/janke-learning/function-exercises/blob/master/examples-to-study.md) \ No newline at end of file +> references: [javascript.info functions](https://javascript.info/function-basics), [function examples to study](https://github.com/janke-learning/function-exercises/blob/master/examples-to-study.md) + +# Functions + +some exercises to help you understand functions: +* Defining vs. Calling functions + * Defining: when you write the funciton -> function name() {}. This creates the permanent function in memory + * Calling: using the function to compute new values -> name(). This creates a new temporary frame and returns a new value +* Arguments +* Lexical Scope +* Return Values +* tracing values through function calls. + 1. stored in a global variable + 1. passed as argument to a function call + 1. available as a parameter in the new frame + 1. returned as part of a return value + 1. captured in a new global variable + +### Index +* [completed example](#completed-example) +* exercises + * [number 1](#1) + * [number 2](#2) + * [number 3](#3) + * [number 4](#4) + * [number 5](#5) + * [number 6](#6) + * [number 7](#7) + * [number 8](#8) +* [resources](#resources) + +--- + +## Completed Example + +[on pytut](http://www.pythontutor.com/javascript.html#code=function%20f%28param_1,%20param_2,%20param_3%29%20%7B%0A%20%20var%20result%20%3D%20param_2%20%2B%20param_3%20%2B%20param_1%3B%0A%20%20return%20result%3B%0A%7D%3B%0A%0A//%20set%20values%20in%20the%20args%20to%20pass%20the%20assert%0Alet%20arg_1%20%3D%20%22x%22,%20arg_2%20%3D%20%22z%22,%20arg_3%20%3D%20%22y%22%3B%0Alet%20return_val%20%3D%20f%28arg_1,%20arg_2,%20arg_3%29%3B%0A%0Aconsole.assert%28return_val%20%3D%3D%3D%20%22zyx%22,%20%22return_val%20%3D%3D%3D%20%22%20%2B%20return_val%29%3B&curInstr=0&mode=display&origin=opt-frontend.js&py=js&rawInputLstJSON=%5B%5D) +[parsonized](http://janke-learning.github.io/parsonizer/?snippet=function%20f%28param_1,%20param_2,%20param_3%29%20%7B%0A%20%20var%20result%20%3D%20param_2%20%2B%20param_3%20%2B%20param_1%3B%0A%20%20return%20result%3B%0A%7D%3B%0A%0A//%20set%20values%20in%20the%20args%20to%20pass%20the%20assert%0Alet%20arg_1%20%3D%20%22x%22,%20arg_2%20%3D%20%22z%22,%20arg_3%20%3D%20%22y%22%3B%0Alet%20return_val%20%3D%20f%28arg_1,%20arg_2,%20arg_3%29%3B%0A%0Aconsole.assert%28return_val%20%3D%3D%3D%20%22zyx%22,%20%22return_val%20%3D%3D%3D%20%22%20%2B%20return_val%29%3B) +```js +{ // completed example + function f(param_1, param_2, param_3) { + var result = param_2 + param_3 + param_1; + return result; + }; + + // set values in the args to pass the assert + let arg_1 = "x", arg_2 = "z", arg_3 = "y"; + let return_val = f(arg_1, arg_2, arg_3); + + console.assert(return_val === "zyx", "example: return_val === " + return_val); +} +``` + +[TOP](#functions) + +--- + +## Exercises + +### 1 + +[on pytut](http://www.pythontutor.com/live.html#code=function%20f%28param_1,%20param_2,%20param_3%29%20%7B%0A%20%20var%20result%20%3D%20param_3%20%2B%20param_1%20%2B%20param_2%3B%0A%20%20return%20result%3B%0A%7D%3B%0A%0A//%20set%20values%20in%20the%20args%20to%20pass%20the%20assert%0Alet%20arg_1%20%3D%20%22%22,%20arg_2%20%3D%20%22%22,%20arg_3%20%3D%20%22%22%3B%0Alet%20return_val%20%3D%20f%28arg_1,%20arg_2,%20arg_3%29%3B%0A%0Aconsole.assert%28return_val%20%3D%3D%3D%20%22zyx%22,%20%221%3A%20return_val%20%3D%3D%3D%20%22%20%2B%20return_val%29%3B&cumulative=false&curInstr=6&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) +[parsonized](http://janke-learning.github.io/parsonizer/?snippet=function%20f%28param_1,%20param_2,%20param_3%29%20%7B%0A%20%20var%20result%20%3D%20param_3%20%2B%20param_1%20%2B%20param_2%3B%0A%20%20return%20result%3B%0A%7D%3B%0A%0A//%20set%20values%20in%20the%20args%20to%20pass%20the%20assert%0Alet%20arg_1%20%3D%20%22%22,%20arg_2%20%3D%20%22%22,%20arg_3%20%3D%20%22%22%3B%0Alet%20return_val%20%3D%20f%28arg_1,%20arg_2,%20arg_3%29%3B%0A%0Aconsole.assert%28return_val%20%3D%3D%3D%20%22zyx%22,%20%22return_val%20%3D%3D%3D%20%22%20%2B%20return_val%29%3B) +```js +{ // 1 + function f(param_1, param_2, param_3) { + var result = param_3 + param_1 + param_2; + return result; + }; + + // set values in the args to pass the assert + let arg_1 = "", arg_2 = "", arg_3 = ""; + let return_val = f(arg_1, arg_2, arg_3); + + console.assert(return_val === "zyx", "1: return_val === " + return_val); +} +``` + +### 2 + +[on pytut](http://www.pythontutor.com/live.html#code=function%20f%28param_1,%20param_2,%20param_3%29%20%7B%0A%20%20var%20result%20%3D%20param_3%20%2B%20param_1%20%2B%20param_2%3B%0A%20%20return%20result%3B%0A%7D%3B%0A%0A//%20set%20values%20in%20the%20args%20to%20pass%20the%20assert%0Alet%20arg_1%20%3D%20%22%22,%20arg_2%20%3D%20%22%22,%20arg_3%20%3D%20%22%22%3B%0Alet%20return_val%20%3D%20f%28arg_1,%20arg_2,%20arg_3%29%3B%0A%0Aconsole.assert%28return_val%20%3D%3D%3D%20%22yxz%22,%20%22return_val%20%3D%3D%3D%20%22%20%2B%20return_val%29%3B&cumulative=false&curInstr=6&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) +[parsonized](http://janke-learning.github.io/parsonizer/?snippet=function%20f%28param_1%2C%20param_2%2C%20param_3%29%20%7B%0A%20%20var%20result%20%3D%20param_3%20%2B%20param_1%20%2B%20param_2%3B%0A%20%20return%20result%3B%0A%7D%3B%0A%0A%2F%2F%20set%20values%20in%20the%20args%20to%20pass%20the%20assert%0Alet%20arg_1%20%3D%20%22%22%2C%20arg_2%20%3D%20%22%22%2C%20arg_3%20%3D%20%22%22%3B%0Alet%20return_val%20%3D%20f%28arg_1%2C%20arg_2%2C%20arg_3%29%3B%0A%0Aconsole.assert%28return_val%20%3D%3D%3D%20%22yxz%22%2C%20%22return_val%20%3D%3D%3D%20%22%20%2B%20return_val%29%3B) +```js +{ // 2 + function f(param_1, param_2, param_3) { + var result = param_3 + param_1 + param_2; + return result; + }; + + // set values in the args to pass the assert + let arg_1 = "", arg_2 = "", arg_3 = ""; + let return_val = f(arg_1, arg_2, arg_3); + + console.assert(return_val === "yxz", "2: return_val === " + return_val); +} +``` + +### 3 + +[on pytut](http://www.pythontutor.com/live.html#code=function%20f%28param_1,%20param_2,%20param_3%29%20%7B%0A%20%20var%20_%20%3D%20param_2%3B%0A%20%20param_2%20%3D%20param_1%3B%0A%20%20param_1%20%3D%20_%3B%0A%20%20var%20result%20%3D%20param_3%20%2B%20param_1%20%2B%20param_2%3B%0A%20%20return%20result%3B%0A%7D%3B%0A%0A//%20set%20values%20in%20the%20args%20to%20pass%20the%20assert%0Alet%20arg_1%20%3D%20%22%22,%20arg_2%20%3D%20%22%22,%20arg_3%20%3D%20%22%22%3B%0Alet%20return_val%20%3D%20f%28arg_1,%20arg_2,%20arg_3%29%3B%0A%0Aconsole.assert%28return_val%20%3D%3D%3D%20%22yxz%22,%20%22return_val%20%3D%3D%3D%20%22%20%2B%20return_val%29%3B&cumulative=false&curInstr=9&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) +[parsonized](http://janke-learning.github.io/parsonizer/?snippet=function%20f%28param_1%2C%20param_2%2C%20param_3%29%20%7B%0A%20%20var%20_%20%3D%20param_2%3B%0A%20%20param_2%20%3D%20param_1%3B%0A%20%20param_1%20%3D%20_%3B%0A%20%20var%20result%20%3D%20param_3%20%2B%20param_1%20%2B%20param_2%3B%0A%20%20return%20result%3B%0A%7D%3B%0A%0A%2F%2F%20set%20values%20in%20the%20args%20to%20pass%20the%20assert%0Alet%20arg_1%20%3D%20%22%22%2C%20arg_2%20%3D%20%22%22%2C%20arg_3%20%3D%20%22%22%3B%0Alet%20return_val%20%3D%20f%28arg_1%2C%20arg_2%2C%20arg_3%29%3B%0A%0Aconsole.assert%28return_val%20%3D%3D%3D%20%22yxz%22%2C%20%22return_val%20%3D%3D%3D%20%22%20%2B%20return_val%29%3B) +```js +{ // 3 + function f(param_1, param_2, param_3) { + var _ = param_2; + param_2 = param_1; + param_1 = _; + var result = param_3 + param_1 + param_2; + return result; + }; + + // set values in the args to pass the assert + let arg_1 = "", arg_2 = "", arg_3 = ""; + let return_val = f(arg_1, arg_2, arg_3); + + console.assert(return_val === "yxz", "3: return_val === " + return_val); +} +``` + +### 4 + +[on pytut](http://www.pythontutor.com/live.html#code=function%20f%28param_1,%20param_2,%20param_3%29%20%7B%0A%20%20var%20_%20%3D%20param_2%3B%0A%20%20param_2%20%3D%20param_3%3B%0A%20%20param_3%20%3D%20_%3B%0A%20%20var%20result%20%3D%20param_3%20%2B%20param_1%20%2B%20param_2%3B%0A%20%20return%20result%3B%0A%7D%3B%0A%0A//%20set%20values%20in%20the%20args%20to%20pass%20the%20assert%0Alet%20arg_1%20%3D%20%22%22,%20arg_2%20%3D%20%22%22,%20arg_3%20%3D%20%22%22%3B%0Alet%20return_val%20%3D%20f%28arg_1,%20arg_2,%20arg_3%29%3B%0A%0Aconsole.assert%28return_val%20%3D%3D%3D%20%22xyz%22,%20%22return_val%20%3D%3D%3D%20%22%20%2B%20return_val%29%3B&cumulative=false&curInstr=9&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) +[parsonized](http://janke-learning.github.io/parsonizer/?snippet=function%20f%28param_1%2C%20param_2%2C%20param_3%29%20%7B%0A%20%20var%20_%20%3D%20param_2%3B%0A%20%20param_2%20%3D%20param_3%3B%0A%20%20param_3%20%3D%20_%3B%0A%20%20var%20result%20%3D%20param_3%20%2B%20param_1%20%2B%20param_2%3B%0A%20%20return%20result%3B%0A%7D%3B%0A%0A%2F%2F%20set%20values%20in%20the%20args%20to%20pass%20the%20assert%0Alet%20arg_1%20%3D%20%22%22%2C%20arg_2%20%3D%20%22%22%2C%20arg_3%20%3D%20%22%22%3B%0Alet%20return_val%20%3D%20f%28arg_1%2C%20arg_2%2C%20arg_3%29%3B%0A%0Aconsole.assert%28return_val%20%3D%3D%3D%20%22xyz%22%2C%20%22return_val%20%3D%3D%3D%20%22%20%2B%20return_val%29%3B) +```js +{ // 4 + function f(param_1, param_2, param_3) { + var _ = param_2; + param_2 = param_3; + param_3 = _; + var result = param_3 + param_1 + param_2; + return result; + }; + + // set values in the args to pass the assert + let arg_1 = "", arg_2 = "", arg_3 = ""; + let return_val = f(arg_1, arg_2, arg_3); + + console.assert(return_val === "xyz", "4: return_val === " + return_val); +} +``` + +### 5 + +[on pytut](http://www.pythontutor.com/live.html#code=function%20f%28param_1,%20param_2,%20param_3%29%20%7B%0A%20var%20result%20%3D%20param_3%20%2B%20param_1%20%2B%20param_2%3B%0A%20return%20result%3B%0A%7D%3B%0A%0Alet%20x%20%3D%20%22x%22,%20y%20%3D%20%22y%22,%20z%20%3D%20%22z%22%3B%0Alet%20return_val%20%3D%20f%28/*%20pass%20x,%20y%20%26%20z%20in%20the%20right%20order%20*/%29%3B%0A%0Aconsole.assert%28return_val%20%3D%3D%3D%20%22xyz%22,%20%225%3A%20return_val%20%3D%3D%3D%20%22%20%2B%20return_val%29%3B&cumulative=false&curInstr=6&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) +[parsonized](http://janke-learning.github.io/parsonizer/?snippet=function%20f%28param_1%2C%20param_2%2C%20param_3%29%20%7B%0A%20var%20result%20%3D%20param_3%20%2B%20param_1%20%2B%20param_2%3B%0A%20return%20result%3B%0A%7D%3B%0A%0Alet%20x%20%3D%20%22x%22%2C%20y%20%3D%20%22y%22%2C%20z%20%3D%20%22z%22%3B%0Alet%20return_val%20%3D%20f%28%2F*%20pass%20x%2C%20y%20%26%20z%20in%20the%20right%20order%20*%2F%29%3B%0A%0Aconsole.assert%28return_val%20%3D%3D%3D%20%22xyz%22%2C%20%225%3A%20return_val%20%3D%3D%3D%20%22%20%2B%20return_val%29%3B) +```js +{ // 5 + function f(param_1, param_2, param_3) { + var result = param_3 + param_1 + param_2; + return result; + }; + + let x = "x", y = "y", z = "z"; + let return_val = f(/* pass x, y & z in the right order */); + + console.assert(return_val === "xyz", "5: return_val === " + return_val); +} +``` + +### 6 + +[on pytut](http://www.pythontutor.com/live.html#code=function%20f%28param_1,%20param_2,%20param_3%29%20%7B%0A%20var%20result%20%3D%20param_2%20%2B%20param_1%20%2B%20param_3%3B%0A%20return%20result%3B%0A%7D%3B%0A%0Alet%20x%20%3D%20%22x%22,%20y%20%3D%20%22y%22,%20z%20%3D%20%22z%22%3B%0Alet%20return_val%20%3D%20f%28/*%20pass%20x,%20y%20%26%20z%20in%20the%20right%20order%20*/%29%3B%0A%0Aconsole.assert%28return_val%20%3D%3D%3D%20%22xzy%22,%20%226%3A%20return_val%20%3D%3D%3D%20%22%20%2B%20return_val%29%3B&cumulative=false&curInstr=6&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) +[parsonized](http://janke-learning.github.io/parsonizer/?snippet=function%20f%28param_1%2C%20param_2%2C%20param_3%29%20%7B%0A%20var%20result%20%3D%20param_2%20%2B%20param_1%20%2B%20param_3%3B%0A%20return%20result%3B%0A%7D%3B%0A%0Alet%20x%20%3D%20%22x%22%2C%20y%20%3D%20%22y%22%2C%20z%20%3D%20%22z%22%3B%0Alet%20return_val%20%3D%20f%28%2F*%20pass%20x%2C%20y%20%26%20z%20in%20the%20right%20order%20*%2F%29%3B%0A%0Aconsole.assert%28return_val%20%3D%3D%3D%20%22xzy%22%2C%20%226%3A%20return_val%20%3D%3D%3D%20%22%20%2B%20return_val%29%3B) +```js +{ // 6 + function f(param_1, param_2, param_3) { + var result = param_2 + param_1 + param_3; + return result; + }; + + let x = "x", y = "y", z = "z"; + let return_val = f(/* pass x, y & z in the right order */); + + console.assert(return_val === "xzy", "6: return_val === " + return_val); +} +``` + +### 7 + +[on pytut](http://www.pythontutor.com/live.html#code=function%20f%28param_1,%20param_2,%20param_3%29%20%7B%0A%20var%20result%20%3D%20/*%20arrange%20the%20params%20to%20pass%20the%20assert%20*/%3B%0A%20return%20result%3B%0A%7D%3B%0A%0Alet%20arg_1%20%3D%20%22z%22,%20arg_2%20%3D%20%22y%22,%20arg_3%20%3D%20%22x%22%3B%0Alet%20return_val%20%3D%20f%28arg_1,%20arg_2,%20arg_3%29%3B%0A%0Aconsole.assert%28return_val%20%3D%3D%3D%20%22xzy%22,%20%227%3A%20return_val%20%3D%3D%3D%20%22%20%2B%20return_val%29%3B&cumulative=false&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) +[parsonized](http://janke-learning.github.io/parsonizer/?snippet=function%20f%28param_1%2C%20param_2%2C%20param_3%29%20%7B%0A%20var%20result%20%3D%20%2F*%20arrange%20the%20params%20to%20pass%20the%20assert%20*%2F%3B%0A%20return%20result%3B%0A%7D%3B%0A%0Alet%20arg_1%20%3D%20%22z%22%2C%20arg_2%20%3D%20%22y%22%2C%20arg_3%20%3D%20%22x%22%3B%0Alet%20return_val%20%3D%20f%28arg_1%2C%20arg_2%2C%20arg_3%29%3B%0A%0Aconsole.assert%28return_val%20%3D%3D%3D%20%22xzy%22%2C%20%227%3A%20return_val%20%3D%3D%3D%20%22%20%2B%20return_val%29%3B) +```js +{ // 7 + function f(param_1, param_2, param_3) { + var result = /* arrange the params to pass the assert */; + return result; + }; + + let arg_1 = "z", arg_2 = "y", arg_3 = "x"; + let return_val = f(arg_1, arg_2, arg_3); + + console.assert(return_val === "xzy", "7: return_val === " + return_val); +} +``` + +### 8 + +[on pytut](http://www.pythontutor.com/live.html#code=function%20f%28param_1,%20param_2,%20param_3%29%20%7B%0A%20var%20result%20%3D%20/*%20arrange%20the%20params%20to%20pass%20the%20assert%20*/%3B%0A%20return%20result%3B%0A%7D%3B%0A%0Alet%20arg_1%20%3D%20%22z%22,%20arg_2%20%3D%20%22y%22,%20arg_3%20%3D%20%22x%22%3B%0Alet%20return_val%20%3D%20f%28arg_1,%20arg_2,%20arg_3%29%3B%0A%0Aconsole.assert%28return_val%20%3D%3D%3D%20%22yxz%22,%20%228%3A%20return_val%20%3D%3D%3D%20%22%20%2B%20return_val%29%3B&cumulative=false&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) +[parsonized](http://janke-learning.github.io/parsonizer/?snippet=function%20f%28param_1%2C%20param_2%2C%20param_3%29%20%7B%0A%20var%20result%20%3D%20%2F*%20arrange%20the%20params%20to%20pass%20the%20assert%20*%2F%3B%0A%20return%20result%3B%0A%7D%3B%0A%0Alet%20arg_1%20%3D%20%22z%22%2C%20arg_2%20%3D%20%22y%22%2C%20arg_3%20%3D%20%22x%22%3B%0Alet%20return_val%20%3D%20f%28arg_1%2C%20arg_2%2C%20arg_3%29%3B%0A%0Aconsole.assert%28return_val%20%3D%3D%3D%20%22yxz%22%2C%20%228%3A%20return_val%20%3D%3D%3D%20%22%20%2B%20return_val%29%3B) +```js +{ // 8 + function f(param_1, param_2, param_3) { + var result = /* arrange the params to pass the assert */; + return result; + }; + + let arg_1 = "z", arg_2 = "y", arg_3 = "x"; + let return_val = f(arg_1, arg_2, arg_3); + + console.assert(return_val === "yxz", "8: return_val === " + return_val); +} +``` + +--- + +## Resources + +* [pythontutor video](https://www.youtube.com/watch?v=bJUmxDsaduY&list=PLzV58Zm8FuBJFfQN5il3ujx6FDAY8Ds3u&index=6) + +___ +___ +### Janke Learning From d643d063bc173ee6b02ea3d18c3c02470547f4f8 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Thu, 27 Jun 2019 22:17:16 +0200 Subject: [PATCH 46/55] Update README.md --- week-1/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-1/README.md b/week-1/README.md index c6eb99b..b391dce 100644 --- a/week-1/README.md +++ b/week-1/README.md @@ -9,7 +9,7 @@ | :seedling: __[errors: variables](./jl-errors-variables.md)__ | :white_check_mark:| | | | | :seedling: __[varibales: swaps](./jl-variables-swaps.md)__ | :white_check_mark:| | | | | :dash: __[variables: multiple assignments](./jl-variables-multiple.md)__ | | | | | -| :seedling: __[how functions work](./jl-functions.md)__ | | | | | +| :seedling: __[how functions work](./jl-functions.md)__ |:white_check_mark: | | | | | :dash: __[functions: turtle shuffle](./jl-turtle-shuffle.md)__ | | | | | --- From daed43bb2850d3d422e2ac2f0cc1c7cc851d8f59 Mon Sep 17 00:00:00 2001 From: Evan Cole <18554853+colevandersWands@users.noreply.github.com> Date: Thu, 4 Jul 2019 13:35:15 +0200 Subject: [PATCH 47/55] Update README.md --- week-1/README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/week-1/README.md b/week-1/README.md index b391dce..d602e26 100644 --- a/week-1/README.md +++ b/week-1/README.md @@ -2,14 +2,14 @@ | | your Emoji | your comments | coach emoji | coach comments | | --- | --- | --- | --- | --- | -| :seedling: __[fcc basics](./fcc-basic-js-pt-1.md)__: through ```Counting Cards``` | :white_check_mark: | it need a lot practice | | | +| :seedling: __[fcc basics](./fcc-basic-js-pt-1.md)__: through ```Counting Cards``` | :white_check_mark: | it need a lot practice | :white_check_mark: | | | :dash: __[fcc debugging](./fcc-debugging.md)__ | | | | | -| :seedling: __[errors: formatting](./jl-errors-formatting.md)__ | :white_check_mark:| | | | -| :seedling: __[errors: primitives](./jl-errors-primitive-types.md)__ | :white_check_mark:| | | | -| :seedling: __[errors: variables](./jl-errors-variables.md)__ | :white_check_mark:| | | | +| :seedling: __[errors: formatting](./jl-errors-formatting.md)__ | :white_check_mark:| | :white_check_mark: | | +| :seedling: __[errors: primitives](./jl-errors-primitive-types.md)__ | :white_check_mark:| | :white_check_mark: | | +| :seedling: __[errors: variables](./jl-errors-variables.md)__ | :white_check_mark:| | :white_check_mark: | | | :seedling: __[varibales: swaps](./jl-variables-swaps.md)__ | :white_check_mark:| | | | -| :dash: __[variables: multiple assignments](./jl-variables-multiple.md)__ | | | | | -| :seedling: __[how functions work](./jl-functions.md)__ |:white_check_mark: | | | | +| :dash: __[variables: multiple assignments](./jl-variables-multiple.md)__ | | | :warning: | the fourth solution is not correct | +| :seedling: __[how functions work](./jl-functions.md)__ |:white_check_mark: | | :warning: | where are your solutions? | | :dash: __[functions: turtle shuffle](./jl-turtle-shuffle.md)__ | | | | | --- From b27ab846baddba48544308c447d3f69abd9a4987 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Thu, 4 Jul 2019 23:16:23 +0200 Subject: [PATCH 48/55] Update fcc-basic-js-pt-2.md --- week-2/fcc-basic-js-pt-2.md | 194 ++++++++++++++++++++++++++++++++++++ 1 file changed, 194 insertions(+) diff --git a/week-2/fcc-basic-js-pt-2.md b/week-2/fcc-basic-js-pt-2.md index bdcd012..9a11ffb 100644 --- a/week-2/fcc-basic-js-pt-2.md +++ b/week-2/fcc-basic-js-pt-2.md @@ -1,3 +1,197 @@ > complete the rest of [basic JS exercises](https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript) on FCC and paste each of your solutions into this file. This will allow you to use your FCC exercises as a study reference later on > [completed example](https://github.com/AlfiYusrina/hyf-javascript1/blob/master/week1/freecode_camp_solutions.MD) +/* This is a +multi-line comment */ +// This is an in-line comment. + +Variables +// Example +var ourName; + +// Declare myName below this line +var myName; + +//Assigning Value to the variable +// Setup +var a; +var b = 2; + +// Only change code below this line +var a= 7; +b=a; + +//Initializing Variables with the Assignment Operator +// Example +var ourVar = 19; + +// Only change code below this line +var a= 9; + +//Understanding Uninitialized Variables + +// Initialize these three variables +var a=5; +var b=10; +var c="I am a"; + +// Do not change code below this line + +a = a + 1; +b = b + 5; +c = c + " String!"; + + +//Understanding Case Sensitivity in Variables +// Declarations + +var studlyCapVar ; +var properCamelCase; +var titleCaseOver; + +// Assignments +studlyCapVar = 10; +properCamelCase = "A String"; +titleCaseOver = 9000; + +//Add Two Numbers with JavaScript +var sum = 10 + 10; + +//Subtract One Number from Another with JavaScript +var difference = 45 - 33; +//Multiply Two Numbers with JavaScript +var product = 8 * 10; + +//Divide One Number by Another with JavaScript +var quotient = 66 / 33; + +//Increment a Number with JavaScript +var myVar = 87; + +// Only change code below this line and decriment + myVar++; + var myVar = 11; + +// Only change code below this line +myVar--; + +//Create Decimal Numbers with JavaScript +var ourDecimal = 5.7; + +// Only change code below this line +var myDecimal= 5.7; +//Multiply Two Decimals with JavaScript +var product = 2.0 * 2.5; + +// Divide One Decimal by Another with JavaScript +var quotient = 4.4 / 2.0; // Fix this line + +//Finding a Remainder in JavaScript +// Only change code below this line + +var remainder=11%3; +//Compound Assignment With Augmented Addition +var a = 3; +var b = 17; +var c = 12; + +// Only modify code below this line + +a += 12; +b += 9; +c += 7; + +//Compound Assignment With Augmented Subtraction +var a = 11; +var b = 9; +var c = 3; + +// Only modify code below this line + +a -= 6; +b -= 15; +c -= 1; + + +//var a = 5; +var b = 12; +var c = 4.6; + +// Only modify code below this line + +a *=5; +b *var a = 48; +var b = 108; +var c = 33; + +// Only modify code below this line + +a /= 12; +b /= 4; +c /= 11; += 10; + +//scaping Literal Quotes in Strings +In JavaScript, you can escape a quote from considering it as an end of string quote by placing a backslash (\) in front of the quote. + +var myStr = "I am a \"double quoted\" string inside \"double quotes\"."; // Change this line + +//Escape Sequences in Strings +Code Output +\' single quote +\" double quote +\\ backslash +\n newline +\r carriage return +\t tab +\b backspace +\f form feed + +var myStr= "FirstLine\n\t\\SecondLine\nThirdLine"; // Change this line + +result FirstLine + \SecondLine +ThirdLine + +//Concatenating Strings with Plus Operator + +// Example +var ourStr = "I come first. " + "I come second."; + +// Only change code below this line + +var myStr= "This is the start. " + "This is the end." ; + +//Concatenating Strings with the Plus Equals Operator +// Example +var ourStr = "I come first. "; +ourStr += "I come second."; + +// Only change code below this line + +var myStr = "This is the first sentence. " ; +myStr +="This is the second sentence."; + +//Constructing Strings with Variables +// Example +var ourName = "freeCodeCamp"; +var ourStr = "Hello, our name is " + ourName + ", how are you?"; + +// Only change code below this line +var myName="kelemu"; +var myStr = "My name is " + myName + " and I am well!"; + + + + +var a = 48; +var b = 108; +var c = 33; + +// Only modify code below this line + +a /= 12; +b /= 4; +c /= 11; + + From 392d750327f45651dc169731ac7ce2e64872c701 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Thu, 11 Jul 2019 14:10:54 +0200 Subject: [PATCH 49/55] Update jl-errors-arrays.md --- week-2/jl-errors-arrays.md | 83 +++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/week-2/jl-errors-arrays.md b/week-2/jl-errors-arrays.md index c86374f..1d60d2c 100644 --- a/week-2/jl-errors-arrays.md +++ b/week-2/jl-errors-arrays.md @@ -1,3 +1,84 @@ > paste [this markdown](https://raw.githubusercontent.com/janke-learning/error-exercises/master/arrays.md) into this file and fix the errors! > [completed example](https://github.com/AlfiYusrina/hyf-javascript1/blob/master/week1/errors_solutions.MD) (of the old version) -> references: [errors & life-cycle](https://github.com/janke-learning/errors-and-life-cycle), [exercise repo](https://github.com/janke-learning/errors) \ No newline at end of file +> references: [errors & life-cycle](https://github.com/janke-learning/errors-and-life-cycle), [exercise repo](https://github.com/janke-learning/errors) +# Array Errors + + +* [missing closing bracket](#missing-closing-bracket) +* [missing comma](#missing-comma) +* [poorly nested](#poorly-nested) + +--- + +## missing closing bracket + +broken code: +```js +let myArray = [1, 2, 3; +``` +error message: +``` +``` +classification: +* creation phase or execution phase ? +* syntax or semanitc ? + +the fix: +```js +``` +your notes: + +[TOP](#array-errors) + +--- + +## missing comma + +broken code: +```js +let myArray = [1, 2 3]; +``` +error message: +``` +``` +classification: +* creation phase or execution phase ? +* syntax or semanitc ? + +the fix: +```js +``` +your notes: + +[TOP](#array-errors) + +--- + +## poorly nested + +broken code: +```js +let myArray = [ + [1, 2, 3] + [4, 5, 6] + [7, 8, 9] + ]; +``` +error message: +``` +``` +classification: +* creation phase or execution phase ? +* syntax or semanitc ? + +the fix: +```js +``` +your notes: + +[TOP](#array-errors) + + +___ +___ +### Janke Learning From a5549a9da6eef49e62b91cd1b68e6810e5cb147c Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Thu, 11 Jul 2019 14:28:38 +0200 Subject: [PATCH 50/55] Update jl-errors-arrays.md --- week-2/jl-errors-arrays.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/week-2/jl-errors-arrays.md b/week-2/jl-errors-arrays.md index 1d60d2c..902a85d 100644 --- a/week-2/jl-errors-arrays.md +++ b/week-2/jl-errors-arrays.md @@ -15,16 +15,20 @@ broken code: ```js let myArray = [1, 2, 3; + ``` error message: ``` + Unexpected token ; ``` classification: * creation phase or execution phase ? * syntax or semanitc ? +it is creation phase and syntax error the fix: ```js + let myArray = [1, 2, 3]; ``` your notes: @@ -40,13 +44,15 @@ let myArray = [1, 2 3]; ``` error message: ``` +Unexpected number ``` classification: * creation phase or execution phase ? * syntax or semanitc ? - +creation phase and syntax and semanitc the fix: ```js +let myArray = [1, 2, 3]; ``` your notes: @@ -66,13 +72,15 @@ let myArray = [ ``` error message: ``` +redeclaration of let myArray ``` classification: * creation phase or execution phase ? * syntax or semanitc ? - +creation phase and Syntax the fix: ```js +let otherName = [[1, 2, 3], [4, 5, 6], [7, 8, 9] ]; ``` your notes: From 7249a203de4662cc31cdf8f9a8ba991bd481b7e7 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Thu, 11 Jul 2019 14:35:41 +0200 Subject: [PATCH 51/55] Update jl-errors-const.md --- week-2/jl-errors-const.md | 91 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) diff --git a/week-2/jl-errors-const.md b/week-2/jl-errors-const.md index 82a6984..cc80d3a 100644 --- a/week-2/jl-errors-const.md +++ b/week-2/jl-errors-const.md @@ -1,2 +1,91 @@ > paste [this markdown](https://raw.githubusercontent.com/janke-learning/error-exercises/master/const.md) into this file and fix the errors! -> references: [errors & life-cycle](https://github.com/janke-learning/errors-and-life-cycle), [exercise repo](https://github.com/janke-learning/errors) \ No newline at end of file +> references: [errors & life-cycle](https://github.com/janke-learning/errors-and-life-cycle), [exercise repo](https://github.com/janke-learning/errors) + +# Variable Errors + + +### exercises +* [missing variable name](#missing-variable-name) +* [reassigning to constant](#reassigning-to-constant) +* [unassigned const declaration](#unassigned-const-declaration) + +--- + +### missing variable name + +broken code: +```js +const = 5; +``` +error message: +```js +missing variable name +``` +classification: +* creation phase or execution phase ? +* syntax or semanitc ? + +it is creation phase +the fix: +```js +const x=5; +``` +your notes: + +[TOP](#variable-errors) + +--- + + +## reassigning to constant + +broken code: +```js +const a = 9; +a = 0; +``` +error message: +``` +invalid assignment to const `a' +``` +classification: +* creation phase or execution phase ? +* syntax or semanitc ? +creation phase and semantic +the fix: +```js +const = 0; +``` +your notes: + +[TOP](#variable-errors) + +--- + + +## unassigned const declaration + +broken code: +```js +const a; +a = 0; +``` +error message: +``` +missing = in const declaration +``` +classification: +* creation phase or execution phase ? +* syntax or semanitc ? +creation phase +the fix: +```js +const a = 0; +``` +your notes: + +[TOP](#variable-errors) + +___ +___ +### Janke Learning From 59bf1b579f7e928ce4cf1ae153a8d087f0b7a79e Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Thu, 11 Jul 2019 14:38:08 +0200 Subject: [PATCH 52/55] Update README.md --- week-2/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/week-2/README.md b/week-2/README.md index 4b2a67b..bc04a9b 100644 --- a/week-2/README.md +++ b/week-2/README.md @@ -4,11 +4,11 @@ | --- | --- | --- | --- | --- | | :seedling: __[fcc: finish js basics](./fcc-basic-js-pt-2.md) | | | | | | :dash: __[janke: tracing conditionals](./jl-tracing-conditionals.md) | | | | | -| :seedling: __[javascript.info: loops](./jsinfo-loops.md) | | | | | -| :dash: __[janke: loop refactors](./jl-loop-refactors.md) | | | | | -| :seedling: __[fcc: data structures](./fcc-data-structures.md) | | | | | -| :seedling: __[janke: errors const](./jl-errors-const.md) | | | | | -| :seedling: __[janke: errors arrays](./jl-errors-arrays.md) | | | | | +| :seedling: __[javascript.info: loops](./jsinfo-loops.md) |:seedling: | | | | +| :dash: __[janke: loop refactors](./jl-loop-refactors.md) | :seedling:| | | | +| :seedling: __[fcc: data structures](./fcc-data-structures.md) |:seedling: | | | | +| :seedling: __[janke: errors const](./jl-errors-const.md) |:seedling: | | | | +| :seedling: __[janke: errors arrays](./jl-errors-arrays.md) | :seedling:| | | | | :seedling: __[janke: errors objects](./jl-errors-objects.md) | | | | | | :seedling: __[javascript.info: objects](./jsinfo-objects.md) | | | | | | :dash: __[janke: reference types](./jl-reference-types.md) | | | | | From 6fd578fc7f69390c16da1b87232cf0b37cb50171 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Thu, 11 Jul 2019 16:34:10 +0200 Subject: [PATCH 53/55] Update jl-loop-refactors.md --- week-2/jl-loop-refactors.md | 531 ++++++++++++++++++++++++++++++++++++ 1 file changed, 531 insertions(+) diff --git a/week-2/jl-loop-refactors.md b/week-2/jl-loop-refactors.md index d55b4e5..6cd6689 100644 --- a/week-2/jl-loop-refactors.md +++ b/week-2/jl-loop-refactors.md @@ -1 +1,532 @@ > paste [this markdown of exercises](https://raw.githubusercontent.com/colevandersWands/loop-refactors/master/README.md) into this file and complete the exercises! +# Loop Refactors + +At it's simplist _refactoring_ is rewriting code while keeping it's original behavior. In the exercises and examples below you can test your refactors by pasting & running the original code in the console, then pasting & running your refactor in console. If both snippets log the exact same messages you have successfully completed the exercise! + +Learning to refactor loops is one of the best ways to learn how they work without struggling to solve code challenges. As you practice shifting between ```while``` and ```for``` loops you'll begin to recognize the general principles of iteration: +1. initial value +1. advancing operation +1. end condition + +Learning to identify these steps and rewrite loops in different ways will help you with debugging, problem solving & understanding other people's code. + +### INDEX +* [learning objectives](#learning-objectives) +* completed examples + * [for](#for) + * [while](#while) + * [do-while](#do-while) +* exercises + * [for to while (4)](#for-to-while) + * [while to for (4)](#while-to-for) +* [for or while?](#for-or-while) +* [resources](#resources) + + +--- + +## Learning Objectives + +* mastering JS loop syntax +* identifying the 3 key components of an iteration +* shifting easily between loop types +* separating the __structure__ of written code from the __behavior__ of program data + +[TOP](#loop-refactors) + +--- + +## Completed Examples + +### For + + +__[From w3schools](https://www.w3schools.com/js/js_loop_for.asp)__: +> The for loop has the following syntax: +``` +for (statement 1; statement 2; statement 3) { + code block to be executed +} +``` +> Statement 1 is executed (one time) before the execution of the code block. +> Statement 2 defines the condition for executing the code block. +> Statement 3 is executed (every time) after the code block has been executed. + +* [study ```for``` on pytut](http://www.pythontutor.com/live.html#code=//%20for%20loop%0Afor%20%28%20let%20stepper%20%3D%200%3B%20stepper%20%3C%204%3B%20stepper%2B%2B%20%29%20%7B%0A%20%20//%20body%0A%7D%0A%0A%0A&cumulative=false&curInstr=9&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) +* [```for``` loop parsonized](https://janke-learning.github.io/parsonizer/?snippet=%2F%2F%20for%20loop%0Afor%20%28%20let%20stepper%20%3D%200%3B%20stepper%20%3C%204%3B%20stepper%2B%2B%20%29%20%7B%0A%20%20%2F%2F%20body%0A%7D%0A%0A%0A) +* [block scope in for loops](http://www.pythontutor.com/live.html#code=for%20%28var%20x%20%3D%200%3B%20x%20%3C%202%3B%20x%2B%2B%29%20%7B%0A%20%20console.log%28%22x%3A%20%22,%20x%29%3B%0A%7D%0A%0Afor%20%28let%20y%20%3D%200%3B%20y%20%3C%202%3B%20y%2B%2B%29%20%7B%0A%20%20console.log%28%22y%3A%20%22,%20y%29%3B%0A%7D&cumulative=false&curInstr=0&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) - JS does an unexpected thing by creating 2 blocks while stepping through the loop. for now just know that this happens, you can understand why later when you learn about closure. + +_original for loop_ +```js +{ + let result = ''; + console.log("initial result: ", result); + + for ( let stepper = 0; stepper < 3; stepper++ ) { + result += stepper; + console.log(result); + } + + console.log("final result: ", result); +} +``` + +_refactored to while_ +```js +{ + let result = ''; + console.log("initial result: ", result); + + let stepper = 0; + while ( stepper < 3 ) { + result += stepper; + console.log(result); + stepper++; + } + + console.log("final result: ", result); +} +``` + +_refactored to do-while_ +```js +/* + it is not possible to refactor for loops into do-while loops + for loops might never execute their body + do-while loops will always execute their body at least once +*/ +``` + + +[TOP](#loop-refactors) + +--- + +### While + +* [```while``` on pytut](http://www.pythontutor.com/live.html#code=//%20while%20loop%0Alet%20stepper%20%3D%200%3B%0Awhile%20%28%20%20stepper%20%3C%204%20%29%20%7B%0A%20%20//%20body%0A%20%20stepper%2B%2B%3B%3B%0A%7D%0A%0A%0A&cumulative=false&curInstr=10&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) +* [```while``` parsonized](https://janke-learning.github.io/parsonizer/?snippet=%2F%2F%20while%20loop%0Alet%20stepper%20%3D%200%3B%0Awhile%20%28stepper%20%3C%204%29%20%7B%0A%20%20%2F%2F%20body%0A%20%20stepper%2B%2B%3B%0A%7D%0A%0A%0A) + +_original while loop_ +```js +{ + let result = ''; + console.log("initial result: ", result); + + let stepper = 0; + while ( stepper < 3 ) { + result += stepper; + console.log(result); + stepper++; + } + + console.log("final result: ", result); +} +``` + +_refactored to for loop_ +```js +{ + let result = ''; + console.log("initial result: ", result); + + for ( let stepper = 0; stepper < 3; stepper++ ) { + result += stepper; + console.log(result); + } + + console.log("final result: ", result); +} +``` + +_refactored to do-while_ +```js +/* + it is not possible to refactor while loops into do-while loops + while loops might never execute their body + do-while loops will always execute their body at least once +*/ +``` + + +[TOP](#loop-refactors) + +--- + +### Do-While + +* [```do-while``` on pytut](http://www.pythontutor.com/live.html#code=//%20do-while%20loop%0Alet%20stepper%20%3D%200%3B%0Ado%20%7B%0A%20%20//%20body%0A%20%20stepper%2B%2B%3B%0A%7D%20while%20%28stepper%20%3C%204%29%3B%0A%0A%0A&cumulative=false&curInstr=9&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) +* [```do-while``` parsonized](https://janke-learning.github.io/parsonizer/?snippet=%2F%2F%20do-while%20loop%0Alet%20stepper%20%3D%200%3B%0Ado%20%7B%0A%20%20%2F%2F%20body%0A%20%20stepper%2B%2B%3B%0A%7D%20while%20%28stepper%20%3C%204%29%3B%0A%0A%0A) + +_original do-while_ +```js +{ + let result = ''; + console.log("initial result: ", result); + + let stepper = 0; + do { + result += stepper; + console.log(result); + stepper++; + } while (stepper < 3); + + console.log("final result: ", result); +} +``` + +_refactored to while_ +```js +{ + let result = ''; + console.log("initial result: ", result); + + let stepper = 0; + + // do + result += stepper; + console.log(result); + stepper++; + + while (stepper < 3) { + result += stepper; + console.log(result); + stepper++; + } + + console.log("final result: ", result); +} +``` + +_refactored to for_ +```js +{ + let result = ''; + console.log("initial result: ", result); + + let stepper = 0; + + // do + result += stepper; + console.log(result); + + for ( stepper = 1; stepper < 3; stepper++ ) { + result += stepper; + console.log(result); + } + + console.log("final result: ", result); +} +``` + + +[TOP](#loop-refactors) + +--- + + +## Exercises + + +### For to While + +### for -> while 1 + +[practice on pytut](http://www.pythontutor.com/live.html#code=%7B%0A%20%20let%20result%20%3D%200%3B%0A%20%20for%20%28let%20i%20%3D%201%3B%20i%20%3C%2010%3B%20i%20%2B%3D%20result%29%20%7B%0A%20%20%20%20result%20%2B%3D%20i%3B%0A%20%20%20%20console.log%28i%29%3B%0A%20%20%7D%0A%7D%0A//%20refactor%20to%20while%20loop%0A%0Awhile%20%28%29%20%7B%0A%20%20%0A%7D&cumulative=false&curInstr=15&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) + +_original for loop_ +```js +{ + let result = 0; + for (let i = 1; i < 10; i += result) { + result += i; + console.log(i); + } +} +``` + +_refactor to while_ +```js +{ + while () { + + } +} +``` + +[parsonized solution](https://janke-learning.github.io/parsonizer/?snippet=let%20result%20%3D%200%3B%0Alet%20i%20%3D%201%3B%0Awhile%20%28%20i%20%3C%2010%20%29%20%7B%0A%20%20result%20%2B%3D%20i%3B%0A%20%20console.log%28i%29%3B%0A%20%20i%20%2B%3D%20result%3B%0A%7D) + +--- + +### for -> while 2 + +[practice on pytut](http://www.pythontutor.com/live.html#code=for%20%28let%20i%20%3D%20-3%3B%20i%20%3D%3D%3D%2010%20%7C%7C%20i%20%3C%2020%3B%20i%20*%3D%20-1.5%29%20%7B%0A%20%20console.log%28i%29%3B%0A%7D%0A%0A//%20refactor%20to%20while%20loop%0A%0Awhile%20%28%29%20%7B%0A%20%20%0A%7D&cumulative=false&curInstr=0&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) + +_original for loop_ +```js +{ + for (let i = -3; i === 10 || i < 20; i *= -1.5) { + console.log(i); + } +} +``` + +_refactor to while_ +```js +{ + while () { + + } +} +``` + +[parsonized solution](https://janke-learning.github.io/parsonizer/?snippet=let%20i%20%3D%20-3%3B%0Awhile%20%28i%20%3D%3D%3D%2010%20%7C%7C%20i%20%3C%2020%29%20%7B%0A%20%20console.log%28i%29%3B%0A%20%20i%20*%3D%20-1.5%3B%0A%7D) + +--- + +### for -> while 3 + +[practice on pytut](http://www.pythontutor.com/live.html#code=%7B%0A%20%20for%20%28let%20i%20%3D%200,%20j%20%3D%2010%3B%20i%20!%3D%3D%20j%3B%20i%2B%2B,%20j--%29%20%7B%0A%20%20%20%20console.log%28%22i%3A%20%22,%20i%29%3B%0A%20%20%20%20console.log%28%22j%3A%20%22,%20j%29%3B%0A%20%20%20%20console.log%28%22i%20%2B%20j%3A%20%22,%20i%20%2B%20j%29%3B%0A%20%20%7D%0A%7D%0A%0A//%20refactor%20to%20while%20loop%0A%0Awhile%20%28%29%20%7B%0A%20%20%0A%7D&cumulative=false&curInstr=0&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) + +_original for loop_ +```js +{ + for (let i = 0, j = 10; i !== j; i++, j--) { + console.log("i: ", i); + console.log("j: ", j); + console.log("i + j: ", i + j); + } +} +``` + +_refactor to while_ +```js +{ + while () { + + } +} +``` + +[parsonized solution](https://janke-learning.github.io/parsonizer/?snippet=let%20i%20%3D%200%2C%20j%20%3D%2010%3B%0Awhile%20%28%20i%20!%3D%3D%20j%20%29%20%7B%0A%20%20console.log%28%22i%3A%20%22%2C%20i%29%3B%0A%20%20console.log%28%22j%3A%20%22%2C%20j%29%3B%0A%20%20console.log%28%22i%20%2B%20j%3A%20%22%2C%20i%20%2B%20j%29%3B%0A%20%20i%2B%2B%2C%20j--%3B%0A%7D) + +--- + + +### for -> while 4 + +> The logic in this loop is difficult to understand; The goal of these refactors is to recognize the __form__ of your code without worrying about the content. You can easily complete this exercise without understanding what's happening! This is the power of learning reliable refactoring patterns + +[practice on pytut](http://www.pythontutor.com/live.html#code=%7B%0A%20%20const%20mixitup%20%3D%20false%3B%0A%20%20let%20val%3B%0A%20%20for%20%28let%20i%20%3D%20''%3B%20!!i%20!%3D%3D%20true%20%3B%20i%20%3D%20%2Bval%29%20%7B%0A%20%20%20%20val%20%3D%20!i%20%7C%7C%20mixitup%20*%20i%3B%0A%20%20%20%20console.log%28!!val%29%3B%0A%20%20%7D%0A%7D%0A%0A//%20refactor%20to%20while%20loop%0A%0Awhile%20%28%29%20%7B%0A%20%20%0A%7D&cumulative=false&curInstr=0&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) + +_original for loop_ +```js +{ + const mixitup = false; + let val; + for (let i = ''; !!i !== true ; i = +val) { + val = !i || mixitup * i; + console.log(!!val); + } +} +``` + +_refactor to while_ +```js +{ + while () { + + } +} +``` + +[parsonized solution](https://janke-learning.github.io/parsonizer/?snippet=const%20mixitup%20%3D%20false%3B%0Alet%20val%3B%0Alet%20i%20%3D%20''%3B%0Awhile%20%28%20!!i%20!%3D%3D%20true%20%29%20%7B%0A%20%20val%20%3D%20!i%20%7C%7C%20mixitup%20*%20i%3B%0A%20%20console.log%28!!val%29%3B%0A%20%20i%20%3D%20%2Bval%3B%0A%7D) + + + +[TOP](#loop-refactors) + +--- + +### While to For + +### while -> for 1 + +[practice on pytut](http://www.pythontutor.com/live.html#code=let%20x%20%3D%209%3B%0Awhile%20%28x%20%3E%202%29%20%7B%0A%20%20console.log%28x%20*%203%29%3B%0A%20%20x--%3B%0A%7D%0A%0A//%20refactor%20to%20for%20loop%0A%0Afor%20%28%20%3B%20%3B%20%29%20%7B%0A%20%20%0A%7D&cumulative=false&curInstr=0&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) +[parsonized while loop](https://janke-learning.github.io/parsonizer/?snippet=let%20x%20%3D%209%3B%0Awhile%20%28x%20%3E%202%29%20%7B%0A%20%20console.log%28x%20*%203%29%3B%0A%20%20x--%3B%0A%7D) + +_original while loop_ +```js +{ + let x = 9; + while (x > 2) { + console.log(x * 3); + x--; + } +} +``` + +_refactor to for_ +```js +{ + for ( ; ; ) { + + } +} +``` + +--- + +### while -> for 2 + +> the [```++``` operator](https://github.com/janke-learning/expanding/blob/master/worked-in-place-operators.md) does two things in one step, it increments it's variable and returns a value. When used in a while loop condition it does the work of the second & third parts of a for loop statement. + +[practice on pytut](http://www.pythontutor.com/live.html#code=let%20x%20%3D%209%3B%0Awhile%20%28x%2B%2B%20%3C%2020%29%20%7B%0A%20%20console.log%28x%29%3B%0A%7D%0A%0A//%20refactor%20to%20for%20loop%0A%0Afor%20%28%20%3B%20%3B%20/*%20nothing%20goes%20here%20*/%20%29%20%7B%0A%20%20%0A%7D&cumulative=false&curInstr=0&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) + + +_original while loop_ +```js +{ + let x = 9; + while (x++ < 20) { + console.log(x); + } +} +``` + +_refactor to for_ +```js +{ + for ( ; ; /* nothing goes here */ ) { + + } +} +``` + + +--- + +### while -> for 3 + +> for this refactor, write your for loop without using [```++``` operator](https://github.com/janke-learning/expanding/blob/master/worked-in-place-operators.md) in the condition check. we've started the refactor so you can get the idea + +[practice on pytut](http://www.pythontutor.com/live.html#code=/*%20%0Afor%20this%20refactor,%20write%20your%20for%20loop%20without%20using%20%0A%20%20%60%60%60%2B%2B%60%60%60%20in%20the%20condition%20check.%20%0A%20%20we've%20started%20the%20refactor%20so%20you%20can%20get%20the%20idea%0A*/%0A%0Alet%20x%20%3D%209%3B%0Awhile%20%28x%2B%2B%20%3C%2020%29%20%7B%0A%20%20console.log%28x%29%3B%0A%7D%0A%0A//%20refactor%20to%20for%20loop%0A%0Afor%20%28%20%3B%20x%20%3C%20%3B%20x%20%2B%3D%201%20%29%20%7B%0A%20%20%0A%7D&cumulative=false&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) + + +_original while loop_ +```js +{ + let x = 9; + while (x++ < 20) { + console.log(x); + } +} +``` + +_refactor to for_ +```js +{ + for ( ; x < ; x += 1 ) { + + } +} +``` + +--- + +### while -> for 4 + +> for this refactor, write your for loop without using [```++``` operator](https://github.com/janke-learning/expanding/blob/master/worked-in-place-operators.md) in the condition check. we're not starting this one for you + +[practice on pytut](http://www.pythontutor.com/live.html#code=/*%20%0Afor%20this%20refactor,%20write%20your%20for%20loop%20without%20using%20%0A%20%20%60%60%60%2B%2B%60%60%60%20in%20the%20condition%20check.%20%0A%20%20we're%20not%20starting%20this%20one%20for%20you%0A*/%0A%0Alet%20x%20%3D%209%3B%0Awhile%20%28%2B%2Bx%20%3C%2020%29%20%7B%0A%20%20console.log%28x%29%3B%0A%7D%0A%0A//%20refactor%20to%20for%20loop%0A%0Afor%20%28%20%3B%20%3B%20%29%20%7B%0A%20%20%0A%7D&cumulative=false&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) + + +_original while loop_ +```js +{ + let x = 9; + while (++x < 20) { + console.log(x); + } +} +``` + +_refactor to for_ +```js +{ + for ( ; ; ) { + + } +} +``` + +[TOP](#loop-refactors) + +--- + +## For or While + + +__[From StackOverflow](https://stackoverflow.com/questions/8109509/in-which-situations-should-i-use-while-loops-instead-for-loops-in-javascript#)__ +> (This will soon get closed as too subjective, or moved to another forum, but anyway...) +> Obviously any for loop can easily be rewritten using "while". But given the syntax of: + +``` +for ([initialization]; [condition]; [final-expression]) +``` +> that is used by the for loop it is obviously very well suited to situations where there is some simple initialisation and a simple end-of-iteration update or counter increment. Putting all of the loop control logic right there in the loop's opening statement makes it easy to see at a glance what makes the loop tick. +> With a while loop the end-of-iteration processing generally has to happen at the bottom of the loop's body, so it's harder to see at a glance how the loop works, but also that is much more suited to the situation where you have to perform a number of calculations to decide whether to keep the loop going. +> Of course you can shove multiple statements in a for loop initialisation or final-expression by separating them with commas, but if that is anything more complicated than i++, j++, k-- it quickly gets too messy for my taste and a while loop would be a better choice. +> +> -- nnnnnn + +__For__ loops in JavaScript could be considered [syntactic sugar](https://www.quora.com/What-is-syntactic-sugar-in-programming-languages), meaning you can replicate their exact behavior using simpler language features. + +--- + + +## Resources + + +__study tools__ +* [python tutor for JS](http://www.pythontutor.com/live.html#code=&cumulative=false&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) +* [parsonizer](https://janke-learning.org/parsonizer) + +__control-flow visualization__ +* (neither of these tools are perfect. if you find them confusing that's just fine, if they help you all the better!) +* [code2flow](https://code2flow.com/app) +* [flowviz](https://janke-learning.org/flowviz) + +__while loops__ +* [javascript.info](https://javascript.info/while-for#the-while-loop) +* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while) +* [Video](https://www.youtube.com/watch?v=PpbFyLTtpWI) +* [use while instead of for](https://teamtreehouse.com/community/why-use-while-loop-instead-of-for) + +__for loops__ +* [MDN on For Loops](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for) +* [Video + Article](https://www.kirupa.com/html5/loops_in_javascript.htm) +* [StackOverflow](https://stackoverflow.com/questions/39969145/while-loops-vs-for-loops-in-javascript) +* [block scope in for loops](http://www.pythontutor.com/live.html#code=for%20%28var%20x%20%3D%200%3B%20x%20%3C%202%3B%20x%2B%2B%29%20%7B%0A%20%20console.log%28%22x%3A%20%22,%20x%29%3B%0A%7D%0A%0Afor%20%28let%20y%20%3D%200%3B%20y%20%3C%202%3B%20y%2B%2B%29%20%7B%0A%20%20console.log%28%22y%3A%20%22,%20y%29%3B%0A%7D&cumulative=false&curInstr=0&heapPrimitives=nevernest&mode=display&origin=opt-live.js&py=js&rawInputLstJSON=%5B%5D&textReferences=false) - JS does an unexpected thing by creating 2 blocks while stepping through the loop. for now just know that this happens, you can understand why later when you learn about closure. + +__do-while loops__ +* [javascript.info](https://javascript.info/while-for#the-do-while-loop) +* [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/do...while) +* [do vs. while: Tutorial GateWay](https://www.tutorialgateway.org/difference-between-javascript-while-and-do-while-loop/) +* [do vs. while: Digital Ocean](https://www.digitalocean.com/community/tutorials/using-while-and-do-while-loops-in-javascript) + + +__loops__ +* [So many of them!](https://www.hackreactor.com/blog/javascript-loops-difference-between-types-while-for-in) +* [interactive examples](http://www.dofactory.com/tutorial/javascript-loops) + + + + + + +[TOP](#loop-refactors) + +___ +___ +### Janke Learning From cdb830e9348ff62b21b3994def52af25b1d712e6 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Thu, 11 Jul 2019 17:18:09 +0200 Subject: [PATCH 54/55] Update jl-loop-refactors.md --- week-2/jl-loop-refactors.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/week-2/jl-loop-refactors.md b/week-2/jl-loop-refactors.md index 6cd6689..878236a 100644 --- a/week-2/jl-loop-refactors.md +++ b/week-2/jl-loop-refactors.md @@ -247,11 +247,15 @@ _original for loop_ _refactor to while_ ```js -{ - while () { +let result = 0; +undefined +let x=0; +while(x<10) +{ + result += x; + x++ + }; - } -} ``` [parsonized solution](https://janke-learning.github.io/parsonizer/?snippet=let%20result%20%3D%200%3B%0Alet%20i%20%3D%201%3B%0Awhile%20%28%20i%20%3C%2010%20%29%20%7B%0A%20%20result%20%2B%3D%20i%3B%0A%20%20console.log%28i%29%3B%0A%20%20i%20%2B%3D%20result%3B%0A%7D) From 990b49dec43f23f521f9dea0ff03a3613ad4a6b9 Mon Sep 17 00:00:00 2001 From: Kelemu <50927723+kelemu-2019@users.noreply.github.com> Date: Thu, 11 Jul 2019 21:31:08 +0200 Subject: [PATCH 55/55] Update jl-errors-objects.md --- week-2/jl-errors-objects.md | 57 ++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/week-2/jl-errors-objects.md b/week-2/jl-errors-objects.md index 73f2eee..4effbc2 100644 --- a/week-2/jl-errors-objects.md +++ b/week-2/jl-errors-objects.md @@ -1,3 +1,58 @@ > paste [this markdown](https://raw.githubusercontent.com/janke-learning/error-exercises/master/objects.md) into this file and fix the errors! > [completed example](https://github.com/AlfiYusrina/hyf-javascript1/blob/master/week1/errors_solutions.MD) (of the old version) -> references: [errors & life-cycle](https://github.com/janke-learning/errors-and-life-cycle), [exercise repo](https://github.com/janke-learning/errors) \ No newline at end of file +> references: [errors & life-cycle](https://github.com/janke-learning/errors-and-life-cycle), [exercise repo](https://github.com/janke-learning/errors) + +# Object Errors + +* [too-far object access](#too-far-object-access) +* [access property directly](#access-property-directly) + +--- + +## too-far object access + +broken code: +```js +let a = {b:3}; +let b = a.b.3 +``` +error message: +``` +``` +classification: +* creation phase or execution phase ? +* syntax or semanitc ? + +the fix: +```js +``` +your notes: + +[TOP](#object-errors) + +--- + +## access property directly +broken code: +```js +let x = {b:'e'}; +let y = b.e; +``` +error message: +``` +``` +classification: +* creation phase or execution phase ? +* syntax or semanitc ? + +the fix: +```js +``` +your notes: + +[TOP](#object-errors) + + +___ +___ +### Janke Learning