-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
70 lines (61 loc) · 2.09 KB
/
script.js
File metadata and controls
70 lines (61 loc) · 2.09 KB
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
let count = 0; // Initialisation
function tickUp() {
count++; // Adds 1
document.getElementById('counter').innerText = count;
}
function tickDown() {
count--; // Subtracts 1
document.getElementById('counter').innerText = count;
}
function runForLoop() {
let result = "";
for (let i = 0; i <= count; i++) {
result += i + " "; // Add the number and a space to a string
}
document.getElementById('forLoopResult').innerText = result;
}
function showOddNumbers() {
let result = "";
for (let i = 1; i <= count; i++) {
if (i % 2 !== 0) { // The % (modulo) checks if there is a remainder
result += i + " ";
}
}
document.getElementById('oddNumberResult').innerText = result;
}
function addMultiplesToArray() {
let multiples = [];
// Start at count, go down to 5, jumping by 1 each time
for (let i = count; i >= 5; i--) {
if (i % 5 === 0) {
multiples.push(i); // Add to the array
}
}
console.log(multiples); // Prints the actual array object
}
function loadCar(carNum) {
// We choose which global variable to use based on the button number
let selectedCar;
if (carNum === 1) selectedCar = carObject1;
if (carNum === 2) selectedCar = carObject2;
if (carNum === 3) selectedCar = carObject3;
// Put the object data into the input fields
document.getElementById('carType').value = selectedCar.cType;
document.getElementById('carMPG').value = selectedCar.cMPG;
document.getElementById('carColor').value = selectedCar.cColor;
}
function printCarObject() {
// This creates a NEW object based on whatever you typed in the boxes
let customCar = {
type: document.getElementById('carType').value,
mpg: document.getElementById('carMPG').value,
color: document.getElementById('carColor').value
};
console.log(customCar);
}
function changeColor(choice) {
const p = document.getElementById('styleParagraph');
if (choice === 1) p.style.color = "red";
if (choice === 2) p.style.color = "green";
if (choice === 3) p.style.color = "blue";
}