mercredi 28 octobre 2015

Why isn't my if condition working?

var cycles = str.split(';;');
for(var c=0; c<cycles.length;c++){// starting cycles loop
    var lines = cycles[c].split('\n');
    for(var l=0;l<lines.length;l++){
        var wrds = lines[l].split(' ');
        for(var w=0;w<wrds.length;w++){
//console.log(varReg);
            var pw = wrds[w-1], cw =wrds[w], sw = wrds[w+1];// previous word, current word and succeding word repectively
            if(cw==='in'){};
//console.log(varReg);            
            if(pw==='doc'){
                if(sw==='setit'|| sw==='position' || sw==='index'){
                    ct+='doc(`'+cw+'`)';    
                }else{
                    ct+='doc(`'+cw+'`);';
                }
            };
//console.log(varReg);            

            if((pw==='get'||pw==='and')){
                if(!(sw!=='get'||sw!=='and'||sw!=='setit'|| sw!=='position' || sw!=='index')){
                ct+='.'+cw+';';
                }else{
                ct+='.'+cw;
                };
            };

            if(pw==='setit' ){
                if(gropdewrds.hasOwnProperty(cw)===false){ ct+='='+ cw+';';}
                else{var temp001 =  
                    ct+='='+ gropdewrds[cw].replace(/([\[\]]+)/g, '`')+';';;
                };
            };

            if(cw==='alert'){
              ct+='alert(' +get_for_alert(cw)+')'; 
            };

            if(sw==='is'){ct+='var '+cw+'='; varReg.push(cw)};

            if((pw==='position'||pw==='index')){
                if((sw==='get'||sw==='and'||sw==='postion'||sw==='setit')){
                    ct+='['+cw+']'
                }else{
                    ct+='['+cw+'];'
                };
            };

            if(pw==='delay'){};// do nothing other function will handle it because it is anytime appearing token
            if((cw in varReg)===true){ct+=cw;};
        }// end of wrds
    }//end of lines
}// end of cycles  
console.log(ct);    
Function(ct)();    
}

it is a piece of a function. and the problem is in last piece of function. and everything is defined

well for instance if str is s is doc #output \n in s get style and backgoundColor 'alicelbue' so the expected answer is var s = doc('#output'); s.style.backgroundColor='aliceblue'; but it is giving me the answer var s = doc('#output'); .style.backgroundColor='aliceblue';.

it is missing s. Why my if condition is not working?

Aucun commentaire:

Enregistrer un commentaire