1.
function nightDayHandler(self){
let selectorBody=document.querySelector('body');
let selectorAll_A=document.querySelectorAll('a');
function setColor(color){
let i=0;
while(i<selectorAll_A.length){
selectorAll_A[i].style.color=color;
i++; } }
if(self.value==='night'){
selectorBody.style.color='white';
selectorBody.style.backgroundColor='black';
setColor('powderblue');
self.value='day';
}else{
selectorBody.style.color='black';
selectorBody.style.backgroundColor='white';
setColor('blue');
self.value='night';
}
}
2.
function nightDayHandler(self){
let selectorBody=document.querySelector('body');
let selectorAll_A=document.querySelectorAll('a');
function setColor(color){
let i=0;
while(i<selectorAll_A.length){
selectorAll_A[i].style.color='color'; // insert ''
i++; } }
if(self.value==='night'){
selectorBody.style.color='white';
selectorBody.style.backgroundColor='black';
setColor(powderblue); // Remove ''
self.value='day';
}else{
selectorBody.style.color='black';
selectorBody.style.backgroundColor='white';
setColor(blue); // Remove ''
self.value='night';
}
}
Number 1 is executed and number 2 is not executed... Can't we add '' to the setColor parameter? I'd appreciate it if you could answer me ㅠ<
java javascript parameter
'powderblue'
represents a string
powderblue
represents a variable.
You should use let powderblue = 'powderblue';
and then use it. It seems that you should not use variables that have not even been declared.
© 2024 OneMinuteCode. All rights reserved.