@@ -7,3 +7,132 @@ help CamperBot build a random
77background color changer
88and help them find and fix errors.
99
10+ Step 1
11+ CamperBot is trying to build out
12+ a random background color changer.
13+ But they keep running into
14+ issues and need your help to debug the code.
15+
16+ CamperBot has already added
17+ the HTML and CSS for the project.
18+ But they are confused as to why
19+ none of the styles and content is showing up on the page.
20+
21+ When they open up the console they see this message:
22+
23+ Example Code
24+ SyntaxError: unknown: Unexpected token, expected "," (5:2)
25+ Syntax errors are thrown when
26+ the JavaScript engine encounters something
27+ it can't interpret. In this case,
28+ it looks like CamperBot has syntax
29+ errors in the darkColorsArr array.
30+
31+ Fix the syntax errors in
32+ the darkColorsArr array and you
33+ should see the content and styles show up on the page.
34+
35+
36+ Step 2
37+ Now, CamperBot is trying to create
38+ a function that will return a random
39+ index from the darkColorsArr.
40+ But they have run into the following error message:
41+
42+ Example Code
43+ Uncaught ReferenceError: math is not defined
44+ A ReferenceError is thrown when
45+ a non-existent variable is referenced.
46+ In this case, it looks like CamperBot
47+ is trying to use math but JavaScript doesn't have a math object.
48+
49+ Fix CamperBot's error in the math.random()
50+ line and open up the console again.
51+
52+
53+ Step 3
54+ Now that the ReferenceError
55+ is resolved, the console is
56+ displaying the correct results
57+ for a random number between 0 and 9.
58+ But CamperBot was not expecting to see decimal numbers like these:
59+
60+ Example Code
61+ 0.015882899879771095
62+ 2.114596286197641
63+ 6.040964780197666
64+ Update the console statement to print a whole number between 0 and 9.
65+
66+ Remember that you worked with a method
67+ in the Role Playing Game that
68+ rounds a number down to the nearest whole number.
69+
70+
71+ Step 4
72+ CamperBot is finished with
73+ building out the getRandomIndex
74+ function and it is working as expected.
75+
76+ But now they are running into
77+ this issue when trying to create
78+ a reference to the body element in the DOM:
79+
80+ Example Code
81+
82+ Uncaught TypeError: document.queryselector
83+ is not a function
84+ A TypeError means that the
85+ code is trying to perform
86+ an operation on a value that
87+ is not of the expected type.
88+
89+ Fix the TypeError by updating
90+ the document.queryselector method
91+ to the correct method name
92+ that selects an element from the DOM.
93+
94+
95+ Step 5
96+ CamperBot has created a new variable
97+ called bgHexCodeSpanElement to
98+ store the reference to the span
99+ element with the id of bg-hex-code.
100+ However, when they try to
101+ log that variable to the console,
102+ they get null.
103+
104+ null is a special value in JavaScript
105+ that represents the absence of a value.
106+ This can happen when you try
107+ to access a property of an object that doesn't exist.
108+
109+ In this case, CamperBot is not
110+ passing in the correct
111+ selector to the document.querySelector method.
112+
113+ Fix the document.querySelector("bg-hex-code")
114+ line so that it correctly selects
115+ the element with the id of bg-hex-code.
116+
117+
118+ Step 6
119+ CamperBot has now created a function
120+ called changeBackgroundColor that changes
121+ the background color of the page to a random color
122+ from the darkColorsArr array.
123+ The function also displays the hex code for that new color.
124+
125+ When they try to test out this function,
126+ they notice that the background
127+ color is not changing and the text shows the following:
128+
129+ Example Code
130+ Hex Code: undefined
131+ undefined is showing up here because
132+ the color variable is not being set correctly.
133+
134+ Fix the error in the darkColorsArr[getRandomIndex]
135+ line so that the color variable is set to a random color
136+ from the darkColorsArr array.
137+
138+
0 commit comments