Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I want to randomly generate a number between 1 and 10 and also display it on a webpage, does anyone have any idea how i'd go about doing this?
preferably in full since i have no idea what im doing
C'mon man. Google something. jsfiddle
var min = 1, max = 10,
num = Math.floor(Math.random() * (max - min + 1)) + min;
document.body.innerHTML = num;
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 2 years ago.
Improve this question
Try printing stars in the following format for n rows.
*
**
for n times
let n = 4;
for (let i = 0; n >= i; i++) {
console.log('*'.repeat(i))
}
Something like this should help you. Please ensure to read contribution guidelines and maybe show what you've tried. This is a simple implementation which should help you.
Good luck!
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
var orangeCost = function (pricePerOrange, amountOfOranges) {
var totalCost = pricePerOrange * amountOfOranges;
console.log(totalCost + " Dollar total cost");
};
orangeCost(5, 5);
25 Dollar total cost
NaN Dollar total cost
Why does it also log the "NaN" part instead of only the 25 Dollar stuff ?
thank you
The only way a multiplication could result in NaN is if the variables were undefined, meaning you're calling the function without passing pricePerOrange or amountOfOranges, or if one of the variables is a string.
Make sure you're passing variables to orangeCost, and that those variables are in fact Numbers.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
Can someone please tell me how to compare elements in array with every other element. I mean in array arr = [a,b,c,d];, I would like to compare a with b,c,d , b with a,c,d, etc. And to do that dynamically, no mather of the size of the array.
Try this:
var a=["a","b","c","d"];
for(var i=0;i<a.length;i++){
for(var j=0;j<a.length;j++){
if(i!=j && a[j]===a[i]){
//match, do whatever you want
}
}
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I'm currently starting to learn Javascript and would be grateful for some help with the following issue:
I'm trying to make a loop that writes a new line with a base value that adds by 1 with each line until the value is equal to 10. Basically, it's supposed to look like this:
Answer: 1
Answer: 2
Answer: 3
... and so on, until it reaches 10. There' the loop should end.
How do I achieve this?
Easy solution. Do not use in anything serious:
for (x=1;x<11;x++)
{
document.write("Answer: "+x+"<br />");
}
More versatile solution with DOM (fiddle):
<p id="numbers">
</p>
<script type="text/javascript">
for (x=1;x<11;x++)
{
document.getElementById("numbers").innerHTML+="Answer: "+x+"<br />"
}
</script>
Use a for loop like so:
for(var x = 1; x <= 10; x++) //start x as equal to one, run the code, and repeat until x is 10
console.log("Answer: " + x);//Print x
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
that's part of my script:
var count = $(".sliderItem").length;
if (count < lp + 5)
{
alert("bp4");
var clips = count-l;
alert("bp5");
}
so the problem is: 'bp4' is visible but 'bp5' not.
when I change var clips = count-1; to var clips = 1; it works fine.
Somebody have some idea?
You don't have var clips = count-1; in your code, you have var clips = count-l;.
Change the letter l (lower case L) to 1 in your code.