Tags | algorithms clean-code deprecated |
Complete these tasks in the correct language. If you are here to learn JavaScript, then do the tasks in JavaScript. If you have been told to use Python then use Python.
Use Git and Github to save your code to the cloud (like a boss).
Please remember that you need to focus on UNDERSTANDING! Some of these exercises are easy but you need to make sure you really understand the concepts that make your code run.
Some of these tasks are kinda easy, but they were all chosen for good reasons. Try think about the lessons each task is trying to teach you. Think about what might confuse other people.
Some of these are difficult. Seek out help when you need it. Always focus on UNDERSTANDING.
A lot of people get the following stuff wrong. Please read this section again before you ask for a review.
A lot of people think it’s a good idea to write lots of comments. They write a line of code and then they write that code out in English. For example
c = a + b // add a and b together and store it in c
This kind of thing is a giant waste of everyone’s time.
Comments can be really useful. But use them sparingly.
Always remember that coders read code. You don’t need to explain every little thing.
Good code uses good function and variable names in order to make its intention clear. Good code documents itself.
Comments are useful if you need to:
//Pythagoras formula
can be a comment on a line that implements the formulamy
or function
The following is bad:
def function # python
function myTriangle // js
If you are giving a function a name, then give it a name that means something. Names matter.
I know a lot of tutorials out there use my
a lot in function and variable names. But you will never see that kind of thing in a professional code base. And now is the time to start building professional habits.
If the instructions say write a function, then please write a function. If you are meant to return a value and you decide to print it instead then that is incorrect.
Good coders are precise and careful. Good coders double check their work and RTFQ (google it).
Make sure your code works before you ask for a review. If it doesn’t work, it will not be accepted.
Good coders pay close attention to detail.
A lot of people like to get their code to ask the user to enter values using the keyboard. Please don’t do that unless it is explicitly requested.
A function’s inputs are its parameters or arguments. We need to see that you know how to drive a function.
Code is read more often than it is written. Get into the habit of writing clean and readable code. This means:
Unless you specifically want to not learn while you are here with us.
Convert this pseudocode into actual code. Make it run. Make sure you understand the results. This is a fundamental lesson:
x = 0
y = 1
Print the value of x
Print the value of y
x = x + 3
y = y + x
Print the value of x
Print the value of y
Check your understanding:
Lots of people think this is easy then get it wrong later. Make sure you check yourself.
Convert this pseudocode into actual code. Make it run. Make sure you understand the results. This is a fundamental lesson. If you don’t understand the results, then spend some time Googling BODMAS.
x = 1 + 1 * 2
y = (1 + 1) * 2
z = 1 + ( 1 * 2 )
a = 1 + 1 * 2 / 2
b = (1 + 1 * 2 ) / 2
print all the things
Check your understanding:
Write a function named hello
, it needs to take in a string as an argument. The function should work like this:
eg: hello("Tshepo")
should output
Hello Tshepo!
Write a function named even_or_odd
or evenOrOdd
. The name of the function depends on the conventions of the language you are writing in. If you don’t know what name to choose then you should check the clean code guidelines.
Your function should take an integer and print in the word “even” or “odd”.
eg: if the input is 3 then the output is “odd”. If the input is 4 then the output is “even”
Write a function that takes in three numbers. These numbers represent the lengths of the sides of a triangle. The function should return the area of a triangle.
This might help: https://www.wikihow.com/Calculate-the-Area-of-a-Triangle
Write a function that takes in three numbers and returns the maximum number.
Do this without using any built-in methods. Write your own logic from scratch.
The function should expect a bunch of numbers, not an array or list.
maximum([1,2,3]) // BAD
maximum(1,2,3) // GOOD
Bonus: How can you change the code so it can take in any number of numbers? Do this without using built-in methods. Write your own logic from scratch.
Again, the function should expect a bunch of numbers as input, not an array or list.
Please do not write a whole new function. Upgrade your existing function.
maximum(1,22,3,2) // this should work
Write a function that takes in a number representing the temperature in Celsius and returns the temperature in Fahrenheit. Write another function that does the opposite (Fahrenheit to Celsius).
Make a function to convert any number into hours and minutes.
For example, 71 will become “1 hour, 11 minutes"; 133 will become “2 hours, 13 minutes".
Most people get this question wrong. Make sure you handle singulars and plurals for both hours and minutes.
Write a function that takes in a string and then prints out all the vowels in the string. Make sure it can deal with capital letters and small letters.
For example, Input: "Umuzi"
, Output: Vowels: u, i
.
Make a function that takes two strings as input, and outputs the common characters/letters that they share.
For example, Input: ‘house’, ‘computers’ . Output: ‘Common letters: o, u, e, s’)