repl.it
@ASutton1986/

Lesson 3: Exercise 2-1

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
const _replaceMe_ = null;

// Remove _replaceMe_ and add your own code so that each variable is the type that its name indicates
const numberVar = 7;
const stringVar = 'H nmnmello';
const booleanVar = true;
const nullVar = "";
const undefinedVar = undefined;

// Remove _replaceMe_ and use math operators to assign the following variables. Use Math methods where ever possible. 
const pi = Math.PI;
const piPlusOne = Math.PI + 1;
const piMinusOne = Math.PI - 1;
const piDividedByThree = Math.PI/3;
const piSquared = (Math.PI * Math.PI);
const piRoundedDown = Math.floor(Math.PI);
const piRoundedUp = Math.ceil(Math.PI);

// Create an if-else statement that will randomly log "Marco" half of the time and "Polo" the other half.  
const random = Math.floor((Math.random() * 100) + 1);
const r = random;
if ((r % 2) === 0)  {
    console.log("Marco!");

} else {
    console.log("Polo!");
}

// Remove _replaceMe_ and assign the variables below using x and y. 
const x = 7.5;
const y = -15;
const isXLessThanY = 7.5 < -15 ;
const xMinusY = 7.5 - (-15) ;
const yDividedByX = y/x;
const xAsAString = (7.5).toString();
const YToThePowerOfX = Math.pow(-15,7.5);
const yRoundedUp = Math.ceil(-15);

//move the console log at the start of the code to greet Evelyn. Do not modify anything else. 
let mysteryVar = 'start value';
console.log(mysteryVar);

const name = 'Evelyn';
const greeting1 = 'Good morrow';
const greeting2 = 'Farewell'

if (name.length < Math.random()*10) {
  mysteryVar = greeting1 + ', ' + name;
} else {
  mysteryVar = greeting2 + ', ' + name;
}

mysteryVar = null;

// Stretch Task: 
// Research the following string methods: includes, indexOf, slice, toUpperCase, toLowerCase
// Using those methods on 'sampleText', correctly remove _replaceMe_ and assign the following variables.
const sampleText = "Isn't documentation great!"
const trueValue = sampleText.includes('great!');
const falseValue = _replaceMe_;
const three = _replaceMe_;
const nine = _replaceMe_;
const cumen = _replaceMe_;
const eat = _replaceMe_;
const DOC = _replaceMe_;
const is = _replaceMe_;
Native Browser JavaScript