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)
Related
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.
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)
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
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
Codes:
g = function () {
H = 3
return H + H
}
f = function () {
Η = 2
return Η + H
}
// 3 + 3 = 6
alert(g())
// 2 + 2 = 5
alert(f())
Live demo:http://jsfiddle.net/qhRJY/light/
While the output is 6 and 5.
It is strange.
Then I try to change the value of the H, the result is still unexpected.
What's the magic here?
In f, the first and second Η are actually the Greek letter Eta, not the Roman H. They look similar, but they're not the same character. It has Unicode code point 0x51377, rather than ASCII code 0x48. So you're adding two different variables.
Would you find the answer unexpected if it were written like this? Because this is equivalent to what you wrote.
g = function () {
H = 3
return H + H
}
f = function () {
Eta = 2
return Eta + H
}
// 3 + 3 = 6
alert(g())
// 2 + 2 = 5
alert(f())
Its a tricky question .Modify the problem with alphabet H.It seems like Roman letters or something special characters.It works fine with 'H' for me.
f = function () {
Η = 3
return Η + H
}
for this code, change to this
f = function () {
I = 3;
return I + I;
}
The 'H' is not cleared from the first function, it's still using the previous value. 2 + 3 = 5
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 8 years ago.
Improve this question
Is it possible to position n divs in between two absolute positioned divs? Im creating some sort of map and would like to draw footprints between two points. I was wondering if i could calculate coordinates of first and second div and determine how many footprints (with fixed width) would go in between and than somehow absolute position them with top and left position.
I don't know how to put this together in jQuery or Javascript.. Any ideas??
Thank you in advance!
Well, this is what I came up with:
Fiddle
There can be as many pairs of points as you wish, one has the class first, the other having the class second, and they will be paired with steps thanks to the following:
var f = $('.first');
var s = $('.second');
f.each(function(i) {
var f2 = f.eq(i);
var s2 = s.eq(i);
var xdist = s2.position().left - f2.position().left;
var ydist = s2.position().top - f2.position().top;
var dist = Math.sqrt(xdist*xdist + ydist*ydist); // Pythagoras
var numOfSteps = Math.round(dist / 50) - 1;
var stepX, stepY;
for (var l = 0; l < numOfSteps; l++) {
stepX = xdist/(numOfSteps+1)*(l+1) +
f2.width()/2 + f2.position().left;
stepY = ydist/(numOfSteps+1)*(l+1) +
f2.height()/2 + f2.position().top;
$('<div></div>').addClass('step').appendTo($(document.body))
.css('left', stepX + 'px')
.css('top' , stepY + 'px');
}
});
It's pretty much understandable without any comments, but if you can't figure out something, feel free to ask.
The number of footprints is calculated here:
var numOfSteps = Math.round(dist / 50) - 1;
and so to change the amount of footprints, change the number 50 to something else (the bigger the number, the less footprints).
Glad to help, was fun coming up with this ;)