-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintro.js
67 lines (45 loc) · 1.27 KB
/
intro.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// 1. alert("message"); -> javascript function
alert('hello');
alert('world');
window.alert('bye');
// convention -> double quotes for string
// idiomatic.js -> living docs of convention in javascript
// 2. Data types -> classifying data
var age = 19
var name = 'Matthew'
// typeof() -> str
alert('My name is '+ name + '(' + typeof(name) + ')')
// Variables
// get input
var name = prompt('What is your name?');
// Naming conventions
// variable names are for everyone, not just you
// always use meaningful names
// camelcase seems to be the norm?
// don't use space
// don't start with numbers
// only use alphabets, number, underscore, $
// string concatetenation (I've done that before)
alert('Hello ' + name)
// string length
alert(name.length)
// string slice
// -> indexing starts from 0
// (start, stop)
alert(name.slice(0,4))
// string uppercase
alert(name.toUpperCase())
// numbers: arithmetic and intro to modulo
// precedence also works btw
// increment and decrement operator
// post and pre in/de crement EXISTS in javascript
var age = 10;
var plusAge = ++age;
// functions -> packaging a block of code
function getMilk(){
alert('start of getMilk()');
alert('Get out of the house');
alert('Buy Milk');
alert('End of getMilk()');
}
getMilk()