From 10eb55ab256caf803feacf0b374f7e912d92a60c Mon Sep 17 00:00:00 2001 From: Stefan Stojanovic Date: Thu, 13 May 2021 20:06:57 +0200 Subject: [PATCH 1/3] Add glossaries for coding insights These can be used to make better hints or instead of the "use these concepts" --- glossary/javascript/js-for-loop.md | 12 ++++++++++++ glossary/javascript/js-function-creation.md | 14 ++++++++++++++ glossary/javascript/js-if-else.md | 19 +++++++++++++++++++ glossary/javascript/js-while-loop.md | 16 ++++++++++++++++ glossary/python/python-for-in-range.md | 19 +++++++++++++++++++ glossary/python/python-for-in.md | 21 +++++++++++++++++++++ glossary/python/python-function-creation.md | 13 +++++++++++++ glossary/python/python-if-elif.md | 18 ++++++++++++++++++ glossary/python/python-while-loop.md | 19 +++++++++++++++++++ 9 files changed, 151 insertions(+) create mode 100644 glossary/javascript/js-for-loop.md create mode 100644 glossary/javascript/js-function-creation.md create mode 100644 glossary/javascript/js-if-else.md create mode 100644 glossary/javascript/js-while-loop.md create mode 100644 glossary/python/python-for-in-range.md create mode 100644 glossary/python/python-for-in.md create mode 100644 glossary/python/python-function-creation.md create mode 100644 glossary/python/python-if-elif.md create mode 100644 glossary/python/python-while-loop.md diff --git a/glossary/javascript/js-for-loop.md b/glossary/javascript/js-for-loop.md new file mode 100644 index 0000000000..f5b0292cbb --- /dev/null +++ b/glossary/javascript/js-for-loop.md @@ -0,0 +1,12 @@ +# For + +A `for` loop is used when you want to execute a piece of code a specified number of times. + + +```javascript +// Create variable i, set the condition to "as long as i is less than 3", increase i by 1 after every loop cycle +for (let i = 0; i < 3; i++) { + // Code that is executed on every cycle + console.log("The current value of i is", i, "."); +} +``` \ No newline at end of file diff --git a/glossary/javascript/js-function-creation.md b/glossary/javascript/js-function-creation.md new file mode 100644 index 0000000000..600df735a2 --- /dev/null +++ b/glossary/javascript/js-function-creation.md @@ -0,0 +1,14 @@ +# Function + +Functions are pieces of code designed for a particular task. + +Functions are executed by performing a function call. + +```javascript +function addition(x, y) { + return x + y; // Returns the sum of x and y +} + +// Function called with values for x and y +addition(11, 3); +``` \ No newline at end of file diff --git a/glossary/javascript/js-if-else.md b/glossary/javascript/js-if-else.md new file mode 100644 index 0000000000..599457b7cd --- /dev/null +++ b/glossary/javascript/js-if-else.md @@ -0,0 +1,19 @@ +# If & if-else + +An `if` is a conditional statement that executes a piece of code if the condition is `true`. + +An `else` statement is used after the `if` and it executes the code if the `if` condition evaluates to `false`. + +`if-else` statements can be nested. + +```javascript +let number = 3; + +if (number > 3) { + console.log(number, "is greater than 3"); +} else if (number < 3) { + console.log(number, "is smaller than 3"); + } else { + console.log(number, "is equal to 3"); + } +``` \ No newline at end of file diff --git a/glossary/javascript/js-while-loop.md b/glossary/javascript/js-while-loop.md new file mode 100644 index 0000000000..1524b1c3a6 --- /dev/null +++ b/glossary/javascript/js-while-loop.md @@ -0,0 +1,16 @@ +# While + +A `while` loop is used when you want to execute a piece of code repeatedly. + +```javascript +let number = 0; + +// while (condition) is true +while (number < 5) { + // Increase number by 1 + number++; + + // Output current value of number + console.log(number); +} +``` \ No newline at end of file diff --git a/glossary/python/python-for-in-range.md b/glossary/python/python-for-in-range.md new file mode 100644 index 0000000000..fa620d7e4f --- /dev/null +++ b/glossary/python/python-for-in-range.md @@ -0,0 +1,19 @@ +# For & range() + +You can use `range()` with a `for..in` loop to cycle through a specified range. + +```python +# For every number in the range 1 to 6 (1 included, 6 excluded) +for number in range(1, 6): + # number to the power of number + print(number ** number) +``` + +Which gives the output: +```plain-text +1 +4 +27 +256 +3125 +``` \ No newline at end of file diff --git a/glossary/python/python-for-in.md b/glossary/python/python-for-in.md new file mode 100644 index 0000000000..33eb7d818e --- /dev/null +++ b/glossary/python/python-for-in.md @@ -0,0 +1,21 @@ +# For...in + +A `for...in` loop is used when you want to iterate over a list, tuple, dictionary, and so on. + +```python +numbers = [1, 3, 2, 5, 9, 4, 7] + +for num in numbers: + print(num) +``` + +The output looks like this: +```plain-text +1 +3 +2 +5 +9 +4 +7 +``` \ No newline at end of file diff --git a/glossary/python/python-function-creation.md b/glossary/python/python-function-creation.md new file mode 100644 index 0000000000..0854afafde --- /dev/null +++ b/glossary/python/python-function-creation.md @@ -0,0 +1,13 @@ +# Function + +Functions are pieces of code designed for a particular task. + +Functions are executed by performing a function call. + +```python +def addition(x, y): + return x + y # Returns the sum of x and y + +# Function called with values for x and y +addition(11, 3) +``` \ No newline at end of file diff --git a/glossary/python/python-if-elif.md b/glossary/python/python-if-elif.md new file mode 100644 index 0000000000..0ea06454cf --- /dev/null +++ b/glossary/python/python-if-elif.md @@ -0,0 +1,18 @@ +# If else + +An `if` is a conditional statement that executes a piece of code if the condition is `true`. + +An `else` statement is used after the `if` and it executes the code if the `if` condition evaluates to `false`. + +`if-else` statements can be nested. + +```python +number = 3 + +if (number > 3): + print("number is greater than", number) +elif (number < 3): + print("number is smaller than", number) +else: + print("number is equal to", number) +``` \ No newline at end of file diff --git a/glossary/python/python-while-loop.md b/glossary/python/python-while-loop.md new file mode 100644 index 0000000000..325116c5dc --- /dev/null +++ b/glossary/python/python-while-loop.md @@ -0,0 +1,19 @@ +# While + +A `while` loop is used when you want to execute a piece of code repeatedly. + +```python +# Ask user for input +number = int(input("Enter a number: ")) + +product = 2 +counter = 1 + +while counter <= number: + # Multiply product by itself + product *= product + # Increase counter + counter = counter+1 + +print("The product is", product) +``` \ No newline at end of file From f844da68f054f9f396467a03232ec182a0a04de2 Mon Sep 17 00:00:00 2001 From: Stefan Stojanovic Date: Fri, 14 May 2021 10:57:53 +0200 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Nemanja Stojanovic --- glossary/javascript/js-if-else.md | 10 +++++----- glossary/python/python-if-elif.md | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/glossary/javascript/js-if-else.md b/glossary/javascript/js-if-else.md index 599457b7cd..353303832d 100644 --- a/glossary/javascript/js-if-else.md +++ b/glossary/javascript/js-if-else.md @@ -4,7 +4,7 @@ An `if` is a conditional statement that executes a piece of code if the conditio An `else` statement is used after the `if` and it executes the code if the `if` condition evaluates to `false`. -`if-else` statements can be nested. +`if-else` statements can be chained. ```javascript let number = 3; @@ -13,7 +13,7 @@ if (number > 3) { console.log(number, "is greater than 3"); } else if (number < 3) { console.log(number, "is smaller than 3"); - } else { - console.log(number, "is equal to 3"); - } -``` \ No newline at end of file +} else { + console.log(number, "is equal to 3"); +} +``` diff --git a/glossary/python/python-if-elif.md b/glossary/python/python-if-elif.md index 0ea06454cf..e8051dfdca 100644 --- a/glossary/python/python-if-elif.md +++ b/glossary/python/python-if-elif.md @@ -4,7 +4,7 @@ An `if` is a conditional statement that executes a piece of code if the conditio An `else` statement is used after the `if` and it executes the code if the `if` condition evaluates to `false`. -`if-else` statements can be nested. +`if-else` statements can be chained. ```python number = 3 @@ -15,4 +15,4 @@ elif (number < 3): print("number is smaller than", number) else: print("number is equal to", number) -``` \ No newline at end of file +``` From 94d43b65da52347a1801e3d4295003dd96ccc7a7 Mon Sep 17 00:00:00 2001 From: Stefan Stojanovic Date: Mon, 17 May 2021 11:35:37 +0200 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3b3827661..ef8c6d0c17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,9 @@ Types of change: ### Fixed - [Linux - Quick cd tips - Fix weird html note](https://github.com/enkidevs/curriculum/pull/2711) +### Added +- [Python & Javascript - Glossary - Add glossary on for, while, if and function creation](https://github.com/enkidevs/curriculum/pull/2708) + ## May 12th 2021 ### Fixed