I wrote my first line of code when I was 19. My mother has a degree in computer engineering and mathematics, but growing up as a girl interested in reading and writing and drawing it never dawned on me, let alone anyone else, that I could want to learn, benefit from learning, or even enjoy coding. Three years later and I’m on my way to becoming a full stack web developer. But I look around at my friends, many of them 2018 college graduates with degrees in the arts and humanities, and I wonder how they could benefit from learning even the most basic fundamentals of programming.
I was excited when my roommate, a recent graduate in Gender Studies and Creative Writing, was assigned to learn HTML and CSS for her job at an independent magazine. The magazine’s founder taught herself to code by building their website entirely herself. And while the site could be rewritten to be more efficient or comprehensible, it stands as a testament to the creativity and effort that was poured into it. My roommate has now learned an impressive amount of HTML and CSS, and I think more young women can benefit from doing the same, and not only for hypertext but for algorithmic languages as well.
1. Strings vs. Numbers & “Print”
3. “if” Logic and Value Comparators
Code nested inside an “if” block will only run if its condition or conditions evaluate as “true”.
4. While Loops
Like “if” blocks, while loops only run if their conditions evaluate to “true”. But a while loop will run repeatedly until its condition is no longer true. It’s important to exercise caution with while loops since you can easily write an infinite loop that could crash your program! If you get stuck in an infinite loop, use the “stop” button so you can edit your code. Check out what happens if you run the infinite loop below . (Code that is “commented out” has two slashes “//” before it and will not be executed. Remove the slashes by highlighting all of the “commented out” content and hitting the command and slash keys at the same time.)
5. For Loops
A for loop is similar to a while loop, but less likely to accidentally create an infinite loop. For loops are ideal for iterating. Note that the “++” means that the iterator will increase by 1 with each loop, and the “- -” means the iterator will decrease by 1.
An object is similar to a string, but its properties do not have indices, and each property holds a key: value pair. Keys are strings, but values can be any data type. Objects are written using curly brackets. You can think of an object like a dictionary. Some coding languages actually use the term “dictionary” instead of “object” for this data type.
8. Const vs. Let & Errors
When declaring a variable, we use “const” or “let” to indicate whether we want to change the value of the variable in the future. Variables written with “const” cannot be changed, and attempting to do so can cause your code to throw errors! But the same variable can be rewritten with no problem if it is instantiated with “let” instead.
9. Try/Catch Blocks
A try/catch block is a very useful way to avoid errors crashing your code. The code inside the try block is executed, and if an error is thrown, it is abandoned and the catch block is executed instead.
10. Functional Programming & Return
You may have noticed that your console displays logs in white, but it also shows a green arrow and another value after it’s finished executing the code. This value is typically not shown on command lines — this is a special feature of Repl.it: it’s showing you the value that the function returned. Most of the functions we’ve written so far don’t return anything, so Repl.it shows the returned value “undefined.” But by including the statement “return _____” we can determine what value will be returned by the function. Keep in mind that a return statement causes the function to stop executing. So we can write a program that accepts parameters, operates on them, and returns altered or updated information. To avoid repeating the same logic in code, we frequently write one function that can be called multiple times. You might notice that some functions have an implicit return value even when no return is specified. Don’t worry about this for now.
11. String Methods
12. Object Methods
Some common object methods include:
Object.hasOwnProperty(propName): Returns a boolean “true” if the object contains a property with the name “propName,” otherwise returns “false.”
Object.keys(): Returns an array containing all of the object’s keys.
Object.values(): Returns an array containing all of the object’s values.
13. Array Methods
Some common array methods include:
Array.sort(): Sorts the array’s elements in ascending order based on unicode values; that is in ascending numerical and then alphabetical order.
Array.push(newElem): Adds the element “newElem” to the end of the array.
Array.pop(): Removes the last element of the array and returns it.
Array.shift(): Removes the first element of the array and returns it.
Array.unshift(newElem): Adds the element “newElem” to the front of the array, pushing each element’s index up 1.
Array.slice(beginning, end): Assuming beginning and end are numbers; returns a new array that contains the elements from indices beginning to end, not including the element at index end.
Array.splice(beginning, deleteCount, newElem): Returns a new array where, beginning at the beginning index, deleteCount elements are removed and the newElem is inserted. To delete a single element at index 3, call Array.splice(3, 1). To insert an element at index 2, call Array.splice(2, 0, newElem). To simply make a copy of the array, call Array.splice()
Array.join(delimiter): Returns a string where every element of the array is concatenated into the string with the given delimiter between each element, or a comma by default. For example, [“banana”, “pancakes”].join() returns “banana,pancakes” but [“banana”, “pancakes”].join(“ “) returns “banana pancakes”.
Here’s a link to the Grace Hopper Program’s site! This is the program that I’m currently enrolled in :)
CodeWars *note: a fun way to practice increasingly challenging algorithmic programming problems. You may find these too challenging at the moment, but I’d highly recommend coming back to them later.
Repl.it *note: a great way to write and run your programs online without installing coding software — very useful if you’re just trying your hand at coding. I used Repl.it to embed the practice problems into this article!