In JS, I’m trying to create an array of randomly selected ascending and descending elements from another array. How can I do this? e.g. let array = [1,2,3,4,5,6,7,8,9,10,11,12] const up = 4 const down = 7 // some code outputRadnomUpDown = [1,3,6,8,11,9,8,6,3,2,1] Thanks for reading. Source: Ask Javascript..
Category : random
How can I generate a random number which is a multiple of a given number while also making sure the number is also within a specified range? const generateMultiple = (multipleOf, min, max) => { //how to implement? } generateMultiple(4, -8, 5) //should return either -8, -4, 0, 4 generateMultiple(2.1, 1, 5) //should return either ..
how can i make my button color change into specific color (white/’ffffff’) IF the random function catch this specific color (‘#8675a9’)? const colButton = document.querySelector(‘.col’) const button1 = document.querySelector(‘.check’) const button2 = document.querySelector(‘.next’) const button3 = document.querySelector(‘.hide’) const terma = document.querySelector(“.term”); const body = document.querySelector(‘body’) const colors = [‘#8675a9’, ‘#f5cab3’, ‘#d1f5d3’, ‘#bad7df’] this is the ..
I want to generate a random number and post it to php. <form method=”post” name=”login_post_form”> <label for=”username”>Username :</label> <input type=”text” name=”username” id=”username” /> <label for=”password”>Password :</label> <input type=”password” name=”password” id=”password” /> <input type=”hidden” name=”randomNumberGen” id=”randomNumberGen” value=”” /> <script> var randomNumber = Math.floor(Math.random() * 1000); document.getElementById(‘randomNumberGen’).value = randomNumber; </script> <input type=”submit” name=”submit” value=”Login” /> </form> It ..
I am working on a password generator but I keep getting RangeError: Maximum call stack size exceeded What does this mean? Here is the code that gives this error… The code is supposed to get the value of the text box when the "Get" button is clicked and use it as the "allowed charaters" when ..
I need to make a rectangle appear randomly somewhere in the canvas, and then it will need to appear randomly in a new place, but I have one problem, it appears a new one but the previous rectangle stay where it was at the beginning and then there are so many rectangles in the canvas, ..
else if (parts[0] === Prefix + ‘number’) { message.channel.send(message.author.username + ‘ What is the minimum number’); if (parts[0] === Math.int) { var MinNum = (Discord.Message); console.log("minimum number is " + MinNum); message.channel.send(message.author.username + ‘ what is the maximum number’); } if (parts[0] === Math.int) { var MaxNum = (Discord.Message); console.log("Maximum number is " + MaxNum); ..
I need to move a rectangle in a random position every 5 seconds, I have this function rectangle(x,y){ var ctx ctx.beginPath(); ctx.rect(20, 20, 15, 10); ctx.stroke(); } function randomMove(){ var myVar; var x; var y; myVar = setInterval( , 5000); x = Math.floor(Math.random() * 10) + 1; y = Math.floor(Math.random() * 10) + 1; rectangle(x,y) ..
I have an array below and I want to get one random item from it. var = ["gm" , "hello" , "dance"," jump","clomb"] Source: Ask Javascript..
I’m trying to get a javascript pick a random line from a textarea. Sorry, big noob here. Currently my code looks like this, and I’m quite sure there are silly mistakes in it. I’m just kinda stuck. First, how do I connect this function to the textarea? Secondly, how do I even output the result? ..
Recent Comments