JavaScript Parameter Question (Chorin...)

Asked 2 years ago, Updated 2 years ago, 72 views

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

2022-09-20 19:00

1 Answers

'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.


2022-09-20 19:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.