Girl Develop It is here to provide affordable and accessible programs to learn software through mentorship and hands-on instruction.
Fully featured web applications
Interactive elements like tabs, sliders, etc
Drawing & animation
<script> CODE GOES HERE </script>
Computers are great at processing. They are bad at understanding.
When you write a program, you must break down every step into simple pieces.
You can see what's going on in the console.
Each instruction in JS is a "statement", like:
console.log('Hello World!'); console.log('I am glad to meet you'); console.log('I am fuzzy');
You can leave comments in your code—notes that people can read but computers will ignore.
/* I can make long comments with multiple lines here */ console.log('Hello World!'); // Or make short comments here
Open a popup box.
Display a message in your console.
Add something to the page.
Just like 'x' in algebra, a variable is a named container for a value that can change.
To declare (create) a variable, just type the word
var and the variable name.
It is a good idea to give your variable a starting value. This is called initializing the variable.
var numberOfKittens = 5;
Once you have created a variable, you can use it in your code. Just type the name of the variable.
var numberOfKittens = 5; console.log(numberOfKittens);
var userName = 'Jane Lane';
var myAge = 30;
var catsAreBest = true;
var goodPickupLines = null;
Variables can be numbers, either integers or floats (decimals).
var numberOfKittens = 5; var cutenessRating = 9.6;
NaN = Not-A-Number
Once you have numbers, you can do math with them!
var numberOfKittens = 5; var numberOfPuppies = 4; var numberOfAnimals = numberOfKittens + numberOfPuppies;
Create two variables and try some arithmetic operators. Don't forget to display your results!
Variables can be strings (groups of characters). You put your string in single or double quotes.
var kittensName = 'Fluffy';
If you want to use a quote in your string, you'll need to escape it with a backslash.
console.log('I\'d like to use an apostrophe');
You can put strings together with a
+, the concatenation operator.
var kittensName = 'Fluffy '; var fullName = kittensName + 'McDougle'; console.log(fullName); // Outputs 'Fluffy McDougle'
You can also use
+= to add things to the end of a string.
var kittensName = 'Admiral '; kittensName += 'Snuggles'; console.log(kittensName); // Outputs 'Admiral Snuggles'
Create two variables, a first name and a last name, and then put them together to make a full name. Don't forget to display your results!
var numberOfFruit = 6; var typeOfFruit = 'bananas'; var allTheFruit = 'I have ' + numberOfFruit + ' ' + typeOfFruit + '!'; console.log(allTheFruit);
Create a program to calculate the tip at a restaurant. It should:
toFixed()to round the bill total to 2 decimals.