所以我有一个语法错误。当我在Codepen编辑器中分析代码时,收到一条错误消息“ undefined(”。这条消息同时出现在第186和200行上。我以前从未见过此错误。
这应该是我自己可以找到的东西,但是在对代码进行了多次通读之后,我似乎无法找出错误所在。我已经通过多个js语法检查器运行了它,但没有任何意义。
此处是指向密码笔的链接:https://codepen.io/Leviathan_The_Great/pen/KqbpdY?editors=1111
这是来源:
let activeGreeting;
function displayGreeting(classSelector){
let greetingHeaders = Array.from( document.getElementsByClassName("greeting-text") );
greetingHeaders = greetingHeaders.map((ElNode)=>{
if( /-?(\.|[_a-zA-Z])+(\.|[_a-zA-Z0-9-])*/.test(ElNode) ){
throw new Error("string passes does not appear to a valid CSS class")
}
if( /^\./m.test(ElNode) ){
return ElNode
}else{
return '.' + ElNode
}
})
let textToShow = document.querySelector(`.greeting-text${classSelector}`);
textToShow.style.display = "block"
}
//scene finding and
var activeScene;
//list of available scenes
const scenes = [document.getElementById('Scene-Day'), document.getElementById('Scene-Night'), document.getElementById("Scene-Valentine's") ];
//main function to calculate the day and which scene to use
(function(){
// for logic testing:
//var date = new Date('December 17, 1995 03:00:00')
//var date = new Date('December 17, 1995 06:25:00')
//var date = new Date('December 17, 1995 12:42:00')
//var date = new Date('December 17, 1995 17:42:00')
//Valentines day 2019
//var date = new Date('1550161356000')
const date = new Date();
const time = date.getHours().toString() + date.getMinutes().toString();
if(date.getDate() === 17 && date.getMonth() === 3){
activeScene=scenes[4];
console.log('its st.patricks day');
}
if(date.getDate() === 31 && date.getMonth() === 10){
activeScene=scenes[5];
console.log("its Halloween day");
}
if(date.getDate() === 14 && date.getMonth() === 2){
activeScene = scenes[3];
console.log("its valentines day");
let greetingText = document.querySelector(".greeting-text.valentine's")
greetingText.style.display = "block";
}else{
console.log("it is not a special day");
//*commented out for scene testing
if (600 <= time && time <= 1200){
activeScene = scenes[0];
let greetingText = document.querySelector(".greeting-text.morning")
greetingText.style.display = "block";
console.log("it is daytime");
}
else if(1200 < time && time <= 1700){
activeScene = scenes[0];
let greetingText = document.querySelector(".greeting-text.afternoon")
greetingText.style.display = "block";
console.log("it is the afternoon")
}
else if(1700 < time && time <= 1700){
activeScene = scenes[1];
let greetingText = document.querySelector(".greeting-text.evening")
greetingText.style.display = "block";
console.log("it is evening");
}
else if(1700 < time && time <= 2400 || time < 600 ){
activeScene = scenes[1];
let greetingText = document.querySelector(".greeting-text.night")
greetingText.style.display = "block";
console.log("it is night");
}
}
})();
(function passiveCloudAnimation(){
function assignSpeedToUndeclaredClouds(clouds, cloudSpeeds){
cloudSpeeds.shift()
let startingArrayLength = cloudSpeeds.length;
for(let i = 0; i < clouds.length - startingArrayLength; i++ ){
let ROV = cloudSpeeds,
range = Math.max(...ROV) - Math.min(...ROV),
randomValInRange = Math.min(...ROV) + ( Math.random() * range );
cloudSpeeds[startingArrayLength] = randomValInRange
}
cloudSpeeds.unshift(null)
return cloudSpeeds
}
/*start of main script*/
let clouds = [],
cloudTLs = [],
cloudSpeeds = [
null,
9,
9.5,
8
];
if( clouds.length > cloudSpeeds.length ){
let cloudSpeedsExtended = f();
cloudSpeeds = assignSpeedToUndeclaredClouds()
}
//retrieve and store clouds
let s_ = document.getElementsByClassName("cloud-container");
s_ = Array.from(s_)
clouds.push(...s_)
for(let i = 1; i < clouds.length; i++){
let tl = new TimelineMax({repeat:-1});
tl.to( `#cloud-${i}`, 9, {transform:"translateX(94vw)", ease:power0.easeNone} )
tl.to( `#cloud-${i}`, 9, {transform:"translateX(0vw)", ease:power0.easeNone} )
cloudTLs.push(tl)
}
clouds.map(()=>{
// code for attaching the event listeners
});
})();
//sets up animation scene
(function setup(){
activeScene.style.display = "initial";
//this is likly why tweenmax is taking a 360 rotation in the next code section
TweenMax.set(document.getElementsByClassName('Scene-Svg'),{rotation:180});
console.log('scene is setup');
})();
(function comeIn(){
//apparently tweenmax is not defined here
TweenMax.to(activeScene, 3, {delay:0.9,rotation:"360_CW",ease:Bounce.easeOut});
console.log('animation entered');
})();
function leave(){
TweenMax.to( activeScene, 1.5, { rotation:'180_CW', ease:Power1.easeOut } );
//TweenMax.to(activeScene,0.4, {delay:3,rotation:360});
console.log('animation has left');
};
function startPassiveAnimation(){
function satelliteAnimation(satelliteClass){
var satelliteContainer = document.querySelector('');
var satellite = document.querySelector('');
return passiveTL.add(TweenMax.set(satelliteContainer,{transformOrigin:'100% 50%', rotation:0}))
.add(TweenMax.to(satelliteContainer,4,{rotation:0}))
.add(TweenMax.to(satellite,3,{rotation:360, repeat:-1}));
}
let satTimeline = satelliteAnimation();
};