[Solved] How to add images in divs randomly using JavaScript?

check this fiddle FIDDLE var limit = 5, amount = 5, lower_bound = 1, upper_bound = 10, unique_random_numbers = []; if (amount > limit) limit = amount; //Infinite loop if you want more unique //Natural numbers than existemt in a // given range while (unique_random_numbers.length < limit) { var random_number = Math.round(Math.random()*(upper_bound – lower_bound) + … Read more

[Solved] How to print a star pattern?

try this code after i==1 create new pattern inside it for (i = 3; i >= 1; i–) { /* Printing spaces */ for (j = 0; j <= 3 – i; j++) { document.write(“&nbsp”); } /* Printing stars */ k = 0; while (k != (2 * i – 1)) { document.write(“*”); k++; } … Read more

[Solved] Profile popups in JavaScript or Jquery [closed]

Your question is a little vague, but for beginners in web design, you might want to use an iframe. It is a HTML tag that creates inline panel/window thing and is pretty easy to use. It looks something like this: <iframe src=”https://stackoverflow.com/questions/18302230/profile.html” width=”300″ height=”300″> <p>Text here will be displayed on a browser that doesn’t support … Read more

[Solved] How to use Foreach data as “this” [closed]

You have several problems with your code, neither of which has to do with accessing this. First, you have ths arguments in the wrong order in the callback. The first argument is the element, the second is the index (maybe you’re used to jQuery — it uses the opposite order in its .each() and .map() … Read more

[Solved] Why are functions synchronous in Javascript?

Javascript has asynchronous operations. But, a for loop is synchronous, not asynchronous. The code you show doesn’t use any asynchronous operations, therefore it’s all synchronous. Should myfunc() execute in node and take longer, so that “end” should be invoked earlier because javascript is asynchronous? No. Nothing in myfunc() is asynchronous. That’s all synchronous code in … Read more

[Solved] Javascript; nested for-loop not working

Arrays are 0-indexed, This means that the last element of an array is not at array.length but at array.length – 1. You’ll have to create a new array (sub-array) and then start adding elements to it. Your code should be like this: var divs = []; for (var x = 0; x < nodeArray.length; x++) … Read more

[Solved] Change all prices (numbers) with 20% on webpage [closed]

Does the following help: var currentMode = 1; var discount = 0.20; var reverseDiscount = 1/(1-discount); function togglePrices() { var prices = document.getElementsByClassName(“price”); for (var i = 0; i < prices.length; i++) { var individualPrice = prices[i].innerHTML.substring(1); if(currentMode == 1) { individualPrice = parseFloat(individualPrice) * (1-discount); } else { individualPrice = parseFloat(individualPrice) * reverseDiscount; } … Read more

[Solved] How to make a string in javascript become incasesensitive?

This question definitely has some quality problems, but here is the solution: let indexOfIgnoreCase = function(x, y) { return x.toLowerCase().indexOf(y.toLowerCase()); } Are you still learning JavaScript? The first statement in your code already returns from the entire function, so you got a bunch of dead code. solved How to make a string in javascript become … Read more

[Solved] HTML Button that opens a panel [closed]

I dont know how familiar you are with CSS and JS, but you can do 2 things: 1. Use a div in the root of the body element, with position:absolute or position:fixed(Depending on your design and layout) and z-index:-100 or whatever is needed to hide it, and then use JS or jQuery to change z-index … Read more