This is the error I'm getting on my console: VM1007:1 Uncaught ReferenceError: getRandomColor is not defined at :1:1
It is saying my function is not defined. Can anyone tell me what I can do to fix this error?
home.js
var color = getColor(6);
var squares = document.querySelectorAll(".square");
//Selects the color you have to pick
var colorSelected = colorSelected();
var randomColor = document.getElementById("randomColor");
var showResponse = document.getElementById("response");
randomColor.textContent = colorSelected;
//add colors to squares
for (var i = 0; i < squares.length; i++){
squares[i].style.backgroundColor = color[i];
//adds click listeners to squares
squares[i].addEventListener("click", function(){
//grab color and compare it to colorSelected
var clicked = this.style.backgroundColor;
if (clicked === colorSelected){
showResponse.textContent ="correct!";
} else{
//fades out so wrong answer disappears
this.style.backgroundColor = "black";
showResponse.textContent = "oops, try again!";
}
});
}
function colorSelected(){
var random = Math.floor((Math.random(color) * 6) + 1);
return color[random];
}
function getColor(num){
//make an array unsure to what to name it yet
var arr = []
for (var i = 0; i < num; i++){
}
//return the array
return arr;
}
//picks a random color from 0 - 255
function getRandomColor(){
var rgb1 = Math.floor((Math.random() * 255) + 1);
var rgb2 = Math.floor((Math.random() * 255) + 1);
var rgb3 = Math.floor((Math.random() * 255) + 1);
return "rgb(rgb1 + rgb2 + rgb3)";
}
I'm not sure what the issue here so some help will be greatly appreciated.