Coder Dojo

Day 3


Instructors: Rohan, Pranay

Open up Coder

code.devoflife.com

Sign back in!

Username: first_lastInitial (example: rohan_b)

Password: ilovecoding!

JS

JavaScript

What's JS?

JS stands for JavaScript.

JavaScript is an actual programming language. Technically, so far we were using markup languages.

How to use JS?

Button method:

							
						

Script tag method:

    
<script>
    alert('hi');
</script>
    

Computer Instructions

Everything is an instruction.

Every line of JS is an instruction your computer runs.

Your computer runs them in order.

Function

A function is a group of instructions that perform a task

Alert Function

			
alert('your message here');
alert('hello ' + 'world!');
            
			

Variables

Variables are a way of storing information in JavaScript

As we saw, you write text to display within quotation marks when dealing with JavaScript.

Similarly, we store text in quotes.

Numbers don't need quotes since they represent a mathematical value instead of text.

			
let applePrice = 5.0;
let userName = 'Rohan';
alert(userName + ' bought an apple for $' + applePrice);
applePrice = applePrice + 1;
alert('Apple prices rose to $' + applePrice + '!');
            
			

Prompt Function

			
let userName = prompt('What is your name?');
alert('Hello ' + userName);
            
			

Button tag

							
						

Result

Your task...

  1. Add at least 3 buttons
  2. Each button should perform an alert
  3. Execute some code on page startup to ask the user questions, then alert your responses.
  4. Style your buttons and add an image button