Krita has been my go-to application for digital drawing and editing. It’s a powerful open-source painting program, on par with professional software like Photoshop, and loved by artists worldwide
Where does Buttonz Booster fit in?
The purpose is to save you some clicks, and it allows you to create a new document with a predefined size, simple and easy.
You can install it directly from Krita, first download the ZIP file
Welcome to the beginning parts of Learn Python In A Normal Way. In this series we’re working on our own Training App. The series focuses on how to get up and running with logical thinking and programming with Python, and it should suit the beginner since doing assignments is what makes you learn quicker.
In this part we’re moving forward with our training app and learn Python if-statements, for-loop introduction and more!
The purpose of this post is to introduce the loops, if statement and conditional logic. Why? Because a lot of programming involves deciding between multiple paths and handling collection of data.
Goal
By the end of this post you can
understand how an if-statement is constructed
understand how to use a for loop in simple scenario
begin to develop boolean conditions in an if-statement
Prerequisites
You must have Python installed and be able to start IDLE to follow along. You should be familiar with how to create modules/script and run a Python script, either from the terminal or the GUI window.
If you found anything difficult in that part, please let us know! Contact Us
Python If-statement – make a choice in your application
A Python If-statement gives you more control over a program. With an if-statement, we use the information of a variable to make a choice in your program. For example, if you want to display all exercises when the user responds “Yes,” and show a different message if the user responds “No,” you can use an if-statement.
Let’s see what they look like!
Code Block to Copy
Try the following code in a new script, which we’ll call workout_v2.py:
week = 1
schedule = 'Workout A'exercises = ('Bench press', 'Deadlift', 'Squat', 'Biceps curl')
response = input('Would you like to see all exercises in the training schedule? (Yes/No) ')
if response == 'Yes':
print('Here are all the exercises:')
# more code here ...elif response == 'No':
print('Okay, we won’t show any exercises right now.')
else:
print('Invalid response, please type "Yes" or "No".')
Python If-statement Analysis
The if-statement in previous listing highlights three branches:
Condition with if: If the user types “Yes,” the code block following the if statement is executed. We call this the first conditional block. The boolean expression (response == ‘Yes’) evaluates to either True or False, depending on what the user typed.
Alternative with elif: If the user types “No,” a different message is displayed.
Invalid response: If the response is something other than “Yes” or “No,” the program shows a message explaining that only those answers are valid.
It’s plain English, yet so important to get it right with Python syntax and indentation. Notice the colon, and the indentation for each block. Otherwise you will get a syntax error when you try to run the program.
Run the code and try typing “Yes,” “No,” and an invalid response (like “Maybe”) to see what happens. You’ll notice that the program becomes more interactive and adapts to the user’s input now. Pretty neat, right?
A note about conditional logic
When we write an if-statement, the code block or the branch to enter is evaluated according to a boolean expression. It’s the same as asking a Yes/No question, but in the computer world we call this True/False result.
The if-statement anatomy consists of the conditional block and the boolean expression
ifTrue:
print("This will always be printed")
When we compared the user’s answer of “Yes” or “No”, the result of that comparison would either be True or False internally.
On the other hand, if we’d write
ifFalse:
print("This will never be printed")
Then we’d never enter that block. Why?
Here are more examples of boolean expressions, where we use the comparion operator greater than >. The first evaluates whether 5 is greater than 10 (False obviously). The second checks if the length of the variable some_list exceeds 100.
if 5 > 10: # Evaluate to Falseprint("5 is greater than 10, is it really?")
iflen(some_list) > 100: # Test if the list has more than 100 elementsprint("You have more than 100 elements in the list")
The purpose is to only execute part of the code when the boolean expression is True. In the above example it’s simply just one print statement. This is something we will see more of and learn about as we move along.
This type of logic becomes important as you want develop the program, also when when you want to put constraints in your program.
Imagine a scenario to never allow more than 5 exercises per workout day, or where you can limit the number of sessions total per week. All these things require some kind of conditional logic to exist in your program. Therefore as you gain experience and develop the program, it’s only you as the designer of the program that can decide what is valid in your program or not.
Finally, let’s look at how to combine multiple expressions, to check several conditions at the same time.
if Expression1 or Expression2:
print("we use the or-condition")
if answer == "Yes"or answer == "yes":
print("You entered Yes...")
The second example becomes handy when you want to let a user be more flexible, you will allow “Yes” and “yes” as an answer to a question, you’ll try to implement this in your program too with the exercises.
Python for-loop – loop through exercises with
Now let’s get back to our program, and look at the first branch i.e. the boolean expression where the user type “Yes” – we’ll introduce the concept of loops now. Remember, the program should display all exercises, according to the question presented to the user
response = input('Would you like to see all exercises in the training schedule? (Yes/No) ')
if response == "Yes":
print("Here are all the exercises:")
for exercise in exercises:
print(exercise)
Notice the construct: keyword for followed by a variable, followed by keyword in followed by a variable (a list or tuple).
for variable1 in variable2
This tells the program to loop through each element in a data structure (like a list or tuple) and execute the code in the loop for each individual element. For our program, it will print each exercise on a separate line, and the output should look like the following. Run the program and confirm you see the same.
Bench press
Deadlift
Squat
Biceps curl
On each iteration print(exercise) works because exercise is bound or assigned the value from the tuple, one value at a time.
In this example:
Starting the loop: for exercise in exercises means that Python starts going through each element in exercises.
Assignment of exercise : For each iteration (loop), exercise becomes the name of one exercise in turn, from ‘Bench press’ to ‘Biceps curl.’
Executing instructions: The code in the loop, print(exercise), is executed each time the loop repeats. So each exercise is printed on its own line.
Insert another statement inside the for-loop block, right above print(exercises) and see the result. Don’t forget to add same indentation.
How many iterations does the loop run?
It depends on the number of elements in the list – the purpose of a for loop is to go through all the elements in the list. The answer is len(exercises), try printing it after the loop.
print("The length of exercises is ", len(exercises))
Alternatively, imagine if you had a really long list, you’d have to print each exercise on its own line. Something that would become cumbersome quickly.
if response == 'Yes':
print(exercises[0])
print(exercises[1])
print(exercises[2])
print(exercises[3])
Now you see the purpose of the the for loop to handle the list (or tuple) efficiently. So, if we had 10 exercises, the for loop wouldn’t change at all. However, you’d have to add 6 more rows of print, which one is better?
Remember a for-loop in Python is a powerful tool for repeating instructions multiple times – perfect for lists and other collections. Using for-loops, we can work efficiently with collections of data and make the program more flexible. Feel free to add your own instructions inside the loop to experiment with how you can handle each element in a list.
if response == 'Yes':
print('Here are all the exercises:')
for exercise in exercises:
print(exercise)
elif response == 'No':
print('Okay, we won’t show any exercises right now.')
else:
print('Invalid response, please type "Yes" or "No".')
Use the operator “in”
Python has a neat operator we can use called in. Let’s demonstrate how to use it in our program. Extend the program by adding a new question asking the user which exercise details to display. In programming terms, we want to search the tuple exercises for a value, namely the exercise the user type into the program dialogue.
As a result, we’ll just print a generic message for each exercise. Add the following after the code above:
selected_exercise = input('Which exercise would you like to know more about? ')
if selected_exercise in exercises:
print(f'You chose {selected_exercise}. This is a fundamental exercise for building strength.')
else:
print('That exercise is not in the schedule.')
Here, we use in to check if the exercise entered by the user exists in exercises. If it does, we display information about the exercise; otherwise, we inform the user that the exercise isn’t in the schedule.
The complete program code
week = 1
schedule = 'Workout A'exercises = ('Bench press', 'Deadlift', 'Squat', 'Biceps curl')
response = input('Would you like to see all exercises in the training schedule? (Yes/No) ')
if response == 'Yes':
print('Here are all the exercises:')
elif response == 'No':
print('Okay, we won’t show any exercises right now.')
else:
print('Invalid response, please type "Yes" or "No".')
selected_exercise = input('Which exercise would you like to know more about? ')
if selected_exercise in exercises:
print(f'You chose {selected_exercise}. This is a fundamental exercise for building strength.')
else:
print('That exercise is not in the schedule.')
Exercises
Extend the exercises tuple with more exercises.
Improve the exercise details, by creating a different messages for each exercise. You’d need to write an if-statements inside an if-statement.
Extend the if-statement to for the word No, with both uppercase and lowercase “N”. The user should be able to enter either “no” or “No”.
Extend the if-statement in previous exercise to allow more alternatives, e.g. “Nope”, “Nah” or whatever you can think of.
In the next part, we’ll use a dictionary to store descriptions for each exercise in a cleaner way.
Another loop is the while-loop, go to docs.python.org to find out more about it. Use the function len() to determine the condition.
Terminology
Review these terms
tuple
list
if-statement
for-loop
boolean expression
Summary
In this part, you’ve seen how to use the if-statements in order to handle different scenarios in your program. It allow your program to become more interactive, but also handle things in the code to work according to your plan. Being able to create different options and decision paths in a program is an important part of programming. It makes your programs more dynamic and user-friendly.
In the next part, we’ll dive deeper into working with loops and explore dictionaries.
In this post, we will begin to explore the fundamental idea of storing information in a Python program. As a matter of fact, the ideas here can be translated to other languages as well.
We will keep it as practical and non-academic as possible, not too much theory at one time, in order to not make it boring.
Purpose
The purpose is to become familiar of basic building blocks of programming and Python. Storing information is where it all begins in a computer program, you must start here and understand how to make the best use out of them.
Goal
By the end of this post you can
create variables and understand why they are necessary
use variables of different types: primitive single-value variables, tuple and list
start to work on the training app we introduce, and which we’ll continue to improve over the course
Prerequisites
You need to have Python installed and be able to start IDLE to follow along. You should be familiar with how to create modules/script and run a Python script, either from the terminal or the GUI window.
Store variables is necessary because a program need to keep track of information while the program is running. The logic in a program is based on logic and information. Since the amount of information is usually more than what the programmer can keep track of in short-term memory, we use variables.
Everyone starts to learn about variables when they write their first computer program.
On a basic level, just remember this:
We use variables as storage in our programs
Variables makes the program easier to read
Variables off-load the programmer’s short-term memory
Variables can contain primitive values like numbers or more complex structures, e.g. like lists of numbers
Code Block to copy
In this section you’re expected to copy and run the code. The purpose is to become familiar with the process. Start IDLE or your environment of choice and copy the code block below.
Run the program If you didn’t encounter any errors, congratulations! You stored your first piece of information in a computer program and should see three lines of output.
name = "Karl"direction = "North"cost = 200
print(name)
print(direction)
print(cost)
The three lines in the output correspond to the three variables: name, direction, cost. These are three different variables, each storing a different type of information.
When you write something within quotation marks, it’s called a “string”, as in the examples “Karl” or “North”. It’s just a piece of text basically, but it’s important to know the correct terminology.
The variable cost, on the other hand, contains a number (integer).
You must remember the following: a variable has a value and a data type.
So far, the data types we’ve seen are string and integer, other types we will encounter later on.
Project – Introducing the Workout App
In order to enhance learning, we will introduce the project for managing workout programs.
Here we will lay the foundation for the program by reusing our knowledge of variables in a real project.
For now, we will focus on tracking which exercises to perform, how many times you’ll train per week, and similar tasks.
Here’s how you can start building the foundation for a real app to create a workout schedule, we will introduce the tuple now.
Run the program
Copy the code into IDLE in a new script and run the program. Print the variableexercises by using the print() function, as we did above.
The only new construct here is the line containing the variable exercises. The right-hand side is a data structure called a tuple. The tuple contains four elements, one for each exercise name. We are still only using variables, pretty cool huh?!
Question: how many exercises should I have? Answer: there’s no limit to how many elements you can have, except for your computer’s capacity, of course.
Now this is enough to consider it a small program, it is similar to a “post-it” note, however since this is programming, we can extend this in a more dynamic fashion as we move along, and we’ll see how quickly this will be useful.
Let’s agree to still call this our minimal program for a Workout App – name it whatever you’d like! Our schedule for week 1 is simple and it’s a program that hold three variables: week, schedule, exercises
Exercises
Add a variable frequency that indicates how many times per week you train. Remember, you only have four exercises, a valid value could be something between 1–4—you decide!
Add new line containing the input function, see code block below. This allows the user to enter a response to the program. Run the program, enter a response, and press Enter. What do you see?
Add a new question to the user, again use input with the question: Which exercise do you want to know more about?. Print the result (the value) from that input. You can use the code block below, remember to change the content between the quotation marks only.
Use this code block where the exercise asks for it
response = input('Do you want to see all the exercises in the workout plan?')
print(response)
When the program runs, it will pause and wait for the user’s input, i.e. press a key. If you don’t press a key, the program could wait indefinitely. So try pressing Enter and see the program finish. In the code, we’ve added a variable response to the left of the input expression.
A note on return values
week = 1
response = input('Do you want to see all the exercises in the workout plan?')
If we compare these two right-hand sides, `1` is called a constant value, and something we as the programmer have assigned to the variable week.
What we need to understand is that input will generate a value, technically it’s the return value of the function. While it doesn’t appear as a number in the code, it will guarantee a value will be be stored in a variable response.
The return value of input will be stored in the variable response. Remember this!
Since we cannot see the value, it’s up to the programmer to either further examine the value or leave it as is. As part of this learning, we decide to print the value.
For now and for a good while ahead, it’s enough to understand and assume that what stands to the right of the equal sign must be an expression that results in a value.
A note about functions in programming
You’ve used input and print as part of Python. Both are called a built-in Python function. Their purpose is to handle communication between the user and the program, they help make the program interactive.
Functions are packaged solutions to common problems for a programmer – as matter of fact, they exist in all languages.
Relying on built-in Python functions can take you a long way, and later we will write our own functions too.
Imagine a carpenter cutting a piece of wood, that could be done with a common tool such as a saw (function). An electric saw would be even better, both are examples of functionality the carpenter can use to help him perform his task. Both are better than trying to cut the piece with bare hands only.
Likewise, the reason print and input are built-in functions is that it’s complex enough for the programmer to handle how a computer “communicates” with a user under-the-hood, and it would be a waste of time to program that logic yourself. Functions hide complex logic in a simple format so that the programmer can have a more enjoyable and easier life.
This principle is called abstraction and something we will explore later.
The complete program code
week = 1
schedule = 'Workout A'exercises = ('Bench press', 'Deadlift', 'Squat', 'Biceps curl')
response = input('Do you want to see all the exercises in the workout plan? (Yes/No)')
print(response) # Prints the user’s response
The program flow is
The program asks the user if it wants to view all the exercises of the workout plan
The user answers the question
The program stores the response (return value) from the function in the variable response.
Reflections
When we build a program, it’s normal to think about the relevant questions needed for the program to function the way you want. This will be a recurring theme in your job as a programmer, it’s important to have an idea and work towards that. It’s important to think this way early to avoid building the “wrong” program, or rather to build the program that suits the user as best as possible.
Remember, we haven’t been precise about what a workout plan should look like, so you must decide how the program should be used as well. This is called requirements analysis in industry language. Translating requirements into code is a major part of writing good programs. The best way to learn is to do it with a real project in mind, that’s the motivation we start with examples early on.
Terminology
Review these terms
string
functions
abstraction
tuple
variable
return value
Summary
In this section, we’ve gone through concepts that can be used to build many different programs. You’ve practiced Python’s built-in functions and saved information in a program.
We have also gone through a simplified process for how a program can be developed. We started with an introductory text and expanded it in several steps by asking the user a question. We also printed the user’s response. This is how programming begins—different parts evolve at different pace.
It’s not easy to do everything at once, so it’s good to think of this process as normal. If someone wants to do everything at once, avoid these personalities at work (hah).
In the next section, we’ll see how to control the flow of a program in different ways and use more Python functions to read text files.
Do you have any ideas right now of how you want to develop your program? After the user enters a response, you can, for example, make the program more user-friendly and ask for details about an exercise.
Installing or updating Python can sometimes be a little tricky and it’s confusing to understand which version is actually installed. Don’t worry in this tutorial we show you how to handle that. One of the downsides of Python is setting up the environment in a correct way and the fact that there are a multitude of installation methods can make the beginner unsure about which Python version is installed.
If you install Visual Studio Code it cannot guarantee that your configuration is in the right place when the time comes to code and run your scripts.
Common ways to install Python
You can download official Python distributions from Python.org, install from a package manager, and even install specialized distributions for scientific computing, Internet of Things, and embedded systems.
This tutorial focuses on official distributions, as they’re generally the best option for getting started with learning to program in Python.
In this tutorial you’ll learn how to:
Check which version of Python, if any, is installed on your machine
Install or update Python on Windows, macOS, and Linux
This is different depending on your operating system. There’s also the option of using Anaconda or even pyenv.
Depending on your use case I’d recommend different options.
Install Python as a beginner for the first time
This method is common for beginners and applies regardless of operating system you are running. The process the most recognizable for newcomers and is highly recommended.
Select the correct version for your operating system. The site should handle it automatically for you. It will look something like the following
Proceed to installing and following the default instructions of the installer.
If you are on Windows, then go to the Start Menu and search for “IDLE”. That should start the default Python interpreter window.
If you are on MacOS then use Spotlight (Command + Space) and search for “IDLE”. Or use Finder to go to Applications -> IDLE
If you are on Linux then you probably need to unzip the artifact/package just downloaded, or in the best case the installer is ready made to just double click.
If you are using Linux
If you are following from the section above, and you are not able to double click the package, then you must probably unzip the package with a tool like, tar, bunzip, gunzip.
If you’re diving right into the terminal, lets first of all check which Python version your Linux distribution comes with.
Sometimes you may have python, python2 or python3 command available, or sometimes all of them. You can check the system Python version as the following
$ python --version
$ python2 --version
$ python3 --version
If any command gives an error, then you don’t have that version installed.
Easier would be, if you type which python then your terminal will show which binary is executed and linked to that python command — given that it exists on your system of course.
If you are using Ubuntu then go ahead and do the following.
$ sudo apt update
$ sudo apt install python3
If the above raises an error, then you need to find which Python-version exists in your package manager and use that when you install. First search for the correct name like this.
$ apt search python
If you are using Windows
Installing on Windows can get a bit complicated, but this guide will hopefully sort things out for you. The most simple method is to go to http://python.org/downloads and download the latest Python version for Windows. If you’re just a beginner then Windows also offers a very simple method through their Microsoft Store. None of these steps below are necessary if you followed the steps in the first section of this post
Install Python via The Microsoft Store method
Open up Microsoft Store and search for Python. Select the latest version and install it.
Do you already have a Python version installed?
Open Powershell by going to Start menu
Type in PowerShell, see screenshot
Type the following in the new PowerShell window: python --version
If you don’t get an error from the last step, then you should see the Python version installed on your Windows system. In this case you don’t need to do anything more.
Step 1 – Locate and open PowerShell
Step 2 – Check Python version if it’s installed
Step 3 – Decide installation method
If you don’t have Python installed already then go ahead and either download Python from the official website or the Microsoft Store
Step 4 – Open up IDLE
This step is the same as earlier, you can start the IDLE program by going to the Start menu and typing “IDLE” like the screenshot below. You see that I have several versions of Python installed at the same time, this is not a problem at all.
EXTRA – Try online editors for Python
You can also try to experiment with Python without installing anything on your computer. Click the following site for example
You will learn the anatomy of a program and what a typical Python program consists of.
Introduce variables, data structures and functions as basic building blocks of a program
Introduce classes and objects as advanced building blocks of a program.
Each building blocks can be used in different ways, and not all of them are required in a single program. Using these blocks, we can gradually construct our program in different ways until we achieve the desired functionality.
By the end of this post, you will have a first introduction of what constitutes a basic Python program by understanding what variables are.
In the next post you will be able to create interactive dialogues with users and store information in variables and data structures.
Data handling is a fundamental of any program so it’s important to understand this early on.
Building Blocks of a Program
Every program is made up of one or more building blocks. We will explore all of them in a series of posts in this blog.
Variables
Data Structures
Functions
Classes
Examples of how building blocks are used
Each building block serves a specific purpose, categorized into storing information (data) or processing it.
Examples of processing information could be:
Calculating VAT given a price.
Determining loan costs based on loan amount and interest rate.
Extracting parts of speech (e.g., verbs, nouns) from a long text or simply calculating the text’s length.
Calculating age based on a birthdate.
Examples of holding (storing) information could be:
Storing personal details throughout a program
Storing account balance
Storing textual information about a book or news site
Here’s an example of some building blocks in a program, feel free to try it out in your Python environment.
Have you not installed Python yet? Check out the simple guide we have
For the examples in this post, it’s sufficient to write them in IDLE. However, if you are already familiar or prefer VSCode, PyCharm or another editor, feel free to do so.
Each file you create are called a module. You may encounter both when you read online resources.
To create a new file in IDLE, go to File -> New File. Name the new file building_blocks_ex1.py.
You will see an empty window where you can write your code. Paste the following code and then go to Run -> Run Module.
name = 'Karl'direction = 'North'cost = 200
print(name)
print(direction)
print(cost)
The example above demonstrates a short program showcasing variables, assignment, and output. The left hand side is the variable name and the right hand side is the value assigned to that variable.
A variable is a container to store data in your program.
Python has many built-in functions that we will use, one of them is the useful print(). That will output to your window the result of each variable we created: name, direction and cost.
Exercise
Practice writing your own variables. Notice the following
What happens if you change single quote to double quotes?
Can you change cost to something other than a number? Like a name?
Create a new variable and name it, e.g. salary, age, points – use your imagination!
Print the newly created variable(s).
What happen if you combine the print like so print(name, direction, cost)?
This was a short introduction to variables and already in the next post we will build on this to interact with a user.
Having your own Discord Bot can be a nice way of adding a custom experience to your users on the server. In order to host your Discord bot, a maintainer has a couple of options to look at before deciding which is the right one. Along the way, there are also a couple of things to take into consideration when you want to host a Discord Bot on your server. You can first of course look if your needs are met by a bot from https://top.gg/. Otherwise you can write your own and for that there are more things to consider.
What to Consider
Which language is the bot written in?
How do you want to host it? What matters to you?
personal support
uptime
monitoring
There are popular languages to write your bot in, some of the popular are
Java
Python
NodeJS.
Host options for a Discord Bot
The common ways to setup a Discord Bot can be
VPS on your own
External hosting provider, in fact that’s exactly what we can help you with. Check out our process and pipeline for deploying the Heaplevel Discord bot here.
Locally on your desktop
Let’s start with the first one VPS. How is the process to get the bot up and running usually?
Discord Bot Hosted on a VPS
Setup VPS by registering a new account at a hosting provider
Login to the VPS and access the terminal
Install the programming environment necessary. This depends on which language you have written your bot in. It could be Python, NodeJS, Java or anything else.
The code. You need a way to transfer the code to the actual VPS machine. Either it’s on a code repository like Github or Bitbucket. Or you can transfer it via some UI file manager. Check with your provider.
When you have the code locally, it’s smart to test run it. this step verifies that you have all the necessary tools for your bot to run. How you do that depends on your code base again. This is probably something you’ve already tried when developing the code locally on your own desktop machine.
If you have verified the code works then it’s time to setup the code to run your server. You can either run your main file as a standalone process, setup a cronjob or write a containerized version of it (link to Docker article – How to run a Docker discord bot).
This step is ususally skipped but if you have the chance to monitor the resource usage on the server it’s a major plus.
Handle updates to the code
Handle bot crashes – due to usage utilization or anything else
With these things we can also support you if you run into problems.
Discord Bot hosted on a external hosting provider
While the registration part is usually the same as for VPS, the real advantage is that an external hosting provider will provide you with an interface for uploading your code and run it. Usually there is an amount of support included in your account. A good hosting provider will allow you to just point to a repository on GitHub or BitBucket for example instead of you manually uploading the files to the server.
The steps are usually
Register your account with the Discord bot hosting provider
Upload your files
Start the bot through the provider’s integrated interface
Discord Bot locally on your desktop
Let’s say you have a little desktop machine laying there without a purpose, you can use it as your local little server. This scenario can look different depending on your setup. But it’s closest to preparing your VPS for Discord Bot. You will need the following
Development environment for the language the bot is written in
Some scheduling and monitoring mechanism if the Discord bot will crash.
If you are sure that everything is complete, then you can run the bot through the development environment on the desktop computer.
Summary
We have looked at different options for setting up your Discord Bot. While they look similar, the decision boils down to what’s important for you. The requirements you have will differ to somebody else. Some are happy with no support from their provider while others are happy to outsource that task to someone else. You still need a fair amount of knowledge to setup the Discord bot on the underlying system, usually in Linux you require a little more experience.
If you find yourself in need of discussing this with us then it’s something we can provide support for. Even if you have support from your provider, drop us an email.
Referring to the above table, we can use different modes for creating a file for the first time. Depending on our purpose if we want to delete an existing file with the same name or not.
If you want to start programming in Javascript you might ask where do you actually start?
It might be that you’ve been interested in learning more about web programming in general, for which it would be useful to also learn about HTML and CSS as well. While HTML and CSS deal with the structure of a website, Javascript adds the dynamic flavour to your website.
There is also a possibility that you want to learn Javascript to write backend applications, using NodeJS. The applications for Javascript are several, both websites and web applications can use Javascript.
If this is the first time to Javascript you can start by learning about the language itself and start play around in a sandbox environment. That is the best option to learn Javascript.
Learn Javascript by examples
We will experiment with Javascript by looking at some examples. This guide is for you that have a little programming background.
This will spin up a Matomo instance on MariaDB running on the default port 3306. You can then access the Matomo instance to continue the installation by navigation to your hostname:3306. E.g. if you’re running this on your VPS it will be your http://<VPS IP>:3306
http://localhost:3306 if you’re on your local dev machine.
The above will not persist your data, in order to do that you need to use volumes on Docker. So if you plan on restarting your Docker container (likely) then you should use volumes. Otherwise when you restart the Docker container you’ll have to reinstall the Matomo instance.
In Javascript comparing values are not always as straightforward as one would expect. Overcoming that fear of which variables are truthy are sometimes is just as easy as learning which values are falsy. If you remember them (6 values) then you can easily know which values are true.
NaN
false
undefined
”, “”, “ – the empty string either single quotes, double quotes or template literalts
0
null
How do you remember these 6 falsy values in Javascript you say? People remember things differently and since all are unique there are many ways to remember.
Remember the simple things first, the one number i.e 0 (zero) is always false. That’s easy to remember right? Also false makes perfect sense to be…you guessed it: false.
So four values to go, look at this: null, NaN, undefined
Finally strings contain text, strings talk, but a string that doesn’t contain anything can’t talk, so it should be false.
The perfect order
0
false
null – NaN – undefined — becomes nullnandefined – null (and) undefined. Those are three values coerced into one to remember easily!
empty strings – can’t talk, should be false then. ”, “”, “