@cheshireoctopus/

Intro Function Arguments

JavaScript

No description

fork
loading
main.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
68
69
70
71
72
/*
  1. Write a function, favoriteAnimal, that accepts an animal as an argument and console.log's something similar to: "I like <ANIMAL>!"
  Ex: favoriteAnimal('cats') should console.log "I like cats!"
*/
function favoriteAnimal(animal) {
  console.log('I like ' + animal)
}

favoriteAnimal('octopus')

/*
  2. Write a function, double, that takes a number and doubles it 
  Ex: double(3) should console.log 6
*/
function double(number) {
  console.log(number * 2)
}

double(5)

/*
  3. Write a function, sum, that takes two numbers and logs their sum
  Ex: sum(4, 5) should console.log 9
*/
function sum(x, y) {
  console.log(x + y)
}

sum(4, 5)


/*
  4. Write a function, areaOfTriangle, that calculates the area of a triangle given its base and height. Hint: the area of a traingle is 1/2 * base * height
  Ex: areaOfTriangle(4, 2) should console.log 4
*/
function areaOfTriangle(base, height) {
  console.log(base * height * 1/2)
}

areaOfTriangle(4, 10)

/*
  5. Write a function, areaOfCircle, that calculates the area of a cirlce given its radius. 
  Hint: the area of a circle is πr^2.
  Another Hint: Use Math.PI to get an approximate value of PI
  
  Ex: areaOfCircle(5) should console.log 78.53981633974483
  Challenge: round the logged value to two decimal places
*/

function areaOfCircle(radius) {
  var area = Math.PI * Math.pow(radius, 2)
  console.log(Math.round(area))
}

areaOfCircle(5)















Native Browser JavaScript