double loops stuck in forever loop [closed] - javascript

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 am trying to loop over my $('.fore-col') and iterate the index position of my api call variables each time incrementing upwards. Starting at 7 and going up by 8 until at the postion of 40. When i run this code, it is stuck in a "forever loop" i believe and didn't stop at the index position of 40. highest count before i pulled the plug was just over 20k.
Any help would be much appreciated!
url: forecastURL,
method: "GET"
}).then(function(res) {
console.log(res);
$(".fore-col").each(function() {
for (let i = 7; i < 40; i + 8) {
let date = res.list[i].dt_txt;
let icon =
"https://openweathermap.org/img/wn/" +
res.list[i].weather +
".png";
let temp = res.list[i].main.temp;
let humid = res.list[i].main.humidity;
console.log(date, icon, temp, humid);
}
});
```
enter code here

for (let i = 7; i < 40; i + 8) should be
for (let i = 7; i < 40; i = i + 8)

Related

Something is wrong with my if and else statement [closed]

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 1 year ago.
Improve this question
Here is my code:
var points = 10
if(points == 10) {
points + 200;
}
else if (points === 100) {
points + 10;
}
console.log(points)
What happens is that it logs 10, when what i would like to happen is that it logs 210. Any idea on what i have done wrong? I got some feedback on it on an earlier question, but it still does not seem to work.
When we use assignment operator we have to use like this:
points = points + 200
so in your code at line "points + 200" or "points + 10" have not changed the value of variable points at all. So, variable points is the same as the first line (var points = 10)
You might modify your program like this:
var points = 10
if(points == 10) {
//points = points +200
points + 200;
}
else if (points === 100) {
//points = points + 10
points + 10;
}
console.log(points)

Just a simple Javascript function to strengthen the core concept of function call [closed]

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 2 years ago.
Improve this question
This gives the output of 0 which means that something is wrong with how I call the factorial function.
function factorial(n) {
let answer = 1;
if (n === 0 || n === 1) {
return answer;
} else {
for (var i = n; i >= 1; i--) {
answer = answer * i;
}
return answer;
}
}
let computation = 0;
function compute(){
let a = 5;
let b = 6
let sum = a + b;
computation = sum + factorial(5);
}
console.log(`The value of this is + ${computation}`);
I don't see you calling compute (i.e. compute()), so computation is still as you initialized it as 0.

Convert integers to string and then adding using recursion [closed]

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 4 years ago.
Improve this question
Hi I am trying to solve a problem where the input for a function digital_root(n) will add the digits. I am not sure what I am doing wrong.
function digital_root(n) {
// ...
//1. separate n into array of digits
var nString = n.toString();
//[ '1', '2', '3', '4' ]
var numbersToAdd = [];
var total = 0;
for (var i = 0; i < nString.length; i++) {
numbersToAdd.push(+nString.charAt(i));
}
// result is [ 1, 2, 3, 4 ]
//2. add digits
for (var x = 0; x < numbersToAdd.length; x++) {
total += numbersToAdd[i];
//expected outputs
// total = 0 + numbersToAdd[0]--> 0+1--> total = 1
// total = 1 + numbersToAdd[1]-->1+2--> total = 3
// total = 3 + numbersToAdd[2]-->3+3--> total = 6
// total = 6 + numbersToAdd[3]-->6+3--> total = 9
}
return total;
}
console.log(digital_root(1234));
You need to use "x" instead of "i"
So changing
total += numbersToAdd[i];
to
total += numbersToAdd[x];
will fix an issue.
Also output should be 10 instead of 9, there is calculation mistake in your question

How was this .js archive encrypted? [closed]

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 7 years ago.
Improve this question
How was this code encrypted? A former webmaster left me code encrypted this way. I do not know how to solve.
Code:
function setCookie(a, b, c) {
var d = new Date();
d[_0x6fff[1]](d[_0x6fff[0]]() + 24 * c * 60 * 60 * 1e3);
var e = _0x6fff[2] + d[_0x6fff[3]]();
document[_0x6fff[4]] = a + _0x6fff[5] + b + _0x6fff[6] + e;
}
function getCookie(a) {
var b = a + _0x6fff[5];
var c = document[_0x6fff[4]][_0x6fff[8]](_0x6fff[7]);
for (var d = 0; d < c[_0x6fff[9]]; d++) {
var e = c[d];
while (_0x6fff[11] == e[_0x6fff[12]](0)) e = e[_0x6fff[10]](1);
if (e[_0x6fff[13]](b) != -1) return e[_0x6fff[10]](b[_0x6fff[9]], e[_0x6fff[9]]);
}
return _0x6fff[14];
}
Looks like it's a combination of minification and Hex-encoded Chinese characters:
Minification is a way of reducing the size of a javascript file by replacing long variable names with single letters (a, b, c in your example above)
_0x6fff is the HEX representation of a HAN character: cross on stepping-stones
Once code has been minified, you can't really undo it. See here

How do I make a numerical array's increase amount smaller in each step? [closed]

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
I would like to make a numeric array which increases in every step.
[1,200,400,600,800,1000, .... , 10000]
But I need to make the amount by which it increases progressively smaller in every step. For example,
[1, 200, 300, 350, 325, 312.5, ....., 10000]
If anybody knows the solution, please give me some ideas.
Thank you.
Change the increment amount as you please...
var arr = [];
var i = 1;
var incrementAmt = 2000;
for(var j = 0; j < 1000; j++) {
var num = i + incrementAmt;
arr.push(num);
i = num;
i++;
incrementAmt = incrementAmt / 2; // cause incrementer to decrease each iteration
}
console.log(arr)

Categories

Resources