Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
i have a slider its not auto-play when i use this j-query code its showing syntax error. But i did'nt find syntax error. Please help
jQuery(document).ready(function () {
var photoslider = new WallopSlider('.photo-slider');
//autoplay
var count = photoslider.allItemsArrayLength;
var start = photoslider.currentItemIndex;
var end = count + 1;
var index = start;
jQuery(function () {
setInterval(function () {
photoslider.goTo(index);
++index;
if (index == end) {
index = start
}
}, 3000);
});
Please put }); after your coding
You forget to put the closing curly braces and parenthesis of jQuery(document).ready(function() {. Which is })
jQuery(document).ready(function () {
var photoslider = new WallopSlider('.photo-slider');
//autoplay
var count = photoslider.allItemsArrayLength;
var start = photoslider.currentItemIndex;
var end = count + 1;
var index = start;
jQuery(function () {
setInterval(function () {
photoslider.goTo(index);
++index;
if (index == end) {
index = start
}
}, 3000);
});
}); //--> this is missing
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 months ago.
Improve this question
Hello I'm new to JS and fetch api. I'm facing a problem that the following code perfectly works and show the datas from that api when I run that code with node and display in on the console. But when I try to show the datas from the api to the browser with JS DOM , it shows 403 error even though I include the authentication in the headers.
fetch('https://od-api.oxforddictionaries.com/api/v2/entries/en-gb/arrow'
, {
method: 'GET',
mode: 'no-cors',
headers: { app_id: "api_id", app_key: "api_key" },
})
.then((response) => response.json())
.then((data) => {
let noun = document.querySelector("#forNoun")
let verb = document.querySelector("#forVerb")
let nounEg = document.querySelector("#nounEg")
let verbEg = document.querySelector('#verbEg')
let searchbtn = document.getElementById("search")
let searchWord = document.getElementById("word")
let nounDef = document.createElement("p");
let verbDef = document.createElement("p")
let lexicalEntries = data.results[0].lexicalEntries;
let length = lexicalEntries.length
for (let i = 0; i < length; i++) {
console.log(lexicalEntries[i].lexicalCategory.text);
nounVerb.innerHTML = lexicalEntries[i].lexicalCategory.text
let senses = lexicalEntries[i].entries[0].senses;
for (let x = 0; x < senses.length; x++) {
if ("examples" && 'synonyms' in senses[x]) {
// console.log(senses[x].definitions[0])
noun.append(senses[x].definitions[0])
}
else if ('examples' in senses[x]) {
noun.append(senses[x].definitions[0])
// console.log(senses[x].definitions[0])
}
else if ('synonyms' in senses[x]) {
noun.append(senses[x].definitions[0])
// console.log(senses[x].definitions[0])
}
else {
noun.append(senses[x].definitions[0])
// console.log(senses[x].definitions[0])
}
}
}
});
`
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
Can anyone help me understand why console.log(this.getPlayerDuration()) inside of setAttendancePromptTimeLimit() is returning NaN?
// video-player.js
const videoP = document.querySelector('#in-course-player')
class videoPlyer {
constructor(videoElem){
this.vidPlayer = videoElem
}
play = function(cb){
arguments.length ? cb : console.log('play')
}
addListener = (elem, event, cb) => {
elem.addEventListener(event, cb)
}
getPlayerCurrentTime = () => this.vidPlayer.currentTime
getPlayerDuration = () => this.vidPlayer.duration
showVideoDuration = function(cb){
arguments.length ? cb : this.addListener(this.vidPlayer, 'loadedmetadata', () =>
console.log(this.getPlayerDuration()))
}
setAttendancePromptTimeLimit = cb => {
// returns NAN
console.log(this.getPlayerDuration())
}
init = () => {
//returns 16.1
this.showVideoDuration()
//returns NAN
this.setAttendancePromptTimeLimit()
}
}
const coursePlayer = new videoPlyer(videoP)
coursePlayer.init()
[...] If no media data is available, the value NaN is returned. [...]
https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/duration
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I have this function:
function addressVerification() {
var del;
let addVer = $('#add_verified').val();
let maddVer = $('#madd_verified').val();
if (addVer == "yes" && maddVer == "yes") {
del = true;
} else {
del = false;
}
return del;
}
When I call it:
$('#add_verified').change(function(){
var ver = addressVerification();
console.info("This is the returned value from the verified address function: "+ ver);
});
It comes back as "undefined."
What am I doing wrong?
You have a syntax error
function addressVerification() {
var del;
let addVer = $('#add_verified').val();
let maddVer = $('#madd_verified').val();
if (addVer == "yes" && maddVer == "yes") {
del = true;
} else {
del = false;
}
} . <----- This is closing the function, ant thus, returning undefined
return del;
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
Does anyone have any idea why i is not defined in this loop? i cannot figure it out...
I'm trying to paginate through the pages of data received from an api and gather it all into one array and store it in state, but my for loop doesn't seem to be working because of the error: "i is not defined"
how else should i go about this???
gatherAllCharacters = () => {
fetch(`https://rickandmortyapi.com/api/character/`)
.then(res => res.json())
.then(data => {
let characters = data.results;
const totalPages = data.info.pages;
if (totalPages > 1) {
for (i = 2; i <= totalPages; i++) {
let page = i;
fetch(`https://rickandmortyapi.com/api/character/?page=${i}`)
.then(res => res.json())
.then(data => {
characters = characters.concat(data.results);
if (page === totalPages) {
this.setState({ allCharacters: characters });
}
});
}
} else {
console.log("none");
}
});
};
You can create a for loop like you have done above
for (i = 2; i <= totalPages; i++) {
//perform loop
}
However this generates a variable i in the global namespace and this is generally speaking a bad idea.
therefore you should initialise i before using it like so:
for (let i = 2; i <= totalPages; i++) {
//perform loop
}
Therefore ECMA decided to have a mode where this (and my other features that would cause undesirable side effects would instead throw an error).
see more here https://www.w3schools.com/js/js_strict.asp
As your app is in use-strict mode it will be throwing the error "i is not defined"
Remember to initialize any variable before using it!
Couple things you should know about let and var
var and let can change their value and const cannot change its value
var can be accessible anywhere in function but let and const can only be accessible inside the block where they are declared.
Because i is not defined. You need a var or let in front of i to define a new variable.
for(let i = 2; i <= totalPages; i++ )
- for (i = 2; i <= totalPages; i++) {
+ for (let i = 2; i <= totalPages; i++) {
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How to send a number to webworker ?
How to receive a number in webworker ?
if possible, How to do this without using json or javascript Object, because using it will add extra line of code ..
EDIT :
ew i got many downvote without knowing why .. i explain what i try to do..
i try to create timer in webworker
if i send string "start" to webworker, webworker will begin the
interval( the timer )
if i send a number to webworker, webworker will set the duration of
interval
but i don't know how to send a number,
i knew argument passed to webworker should be a string, i already read few tutorial,
but i still don't understand what to do so my webworker can recognize a number..
because i try parseInt() and is not work ..
here's my code
in HTML
window.onload = function(){
var worker = new Worker("Thread.js");
worker.postMessage("1500"); //set duration of interval
worker.postMessage("start"); //start the interval
worker.onmessage = function(e){
document.body.innerHTML += '<p> worker receive: '+e.data+'</p>';
}
worker.onerror = function(e){
document.body.innderHTML += "<p> worker error"+e.data+"</p>";
}
}
Thread.js
onmessage = function(e){
var msg = e.data ;
var timer;
var duration = 1000; //default duration
try{
var number = parseInt(msg);
msg = number;
}catch(e){
}
//start the interval
if(msg === "start"){
timer = setInterval(function(){
postMessage( "lalala" );
}, duration);
}
else if(msg === "stop"){
clearInterval(timer);
}
//set duration
else if(!isNaN(msg)){
duration = msg;
}
}
That doesn't work because parseInt doesn't throw an Error, it returns NaN (Not a Number).
You also have another bug: you need to declare timer and duration outside onmessage if you want both to persist between two messages.
Note that changing duration won't affect the interval unless you restart it.
var timer;
var duration = 1000;
onmessage = function(e) {
var msg = e.data ;
var number = parseInt(msg);
if(msg === "start") {
timer = setInterval(function() {
postMessage( "lalala" );
}, duration);
} else if(msg === "stop") {
clearInterval(timer);
} else if(!isNaN(msg)) {
duration = number;
}
};