1

I got this javascript code that returns a random integer number between 1 and 10.

I got a problem making it return a random number between -7 and -12.

You gotta bail me out of this one, please...

const a = Math.floor(Math.random() * (10 - 1)) + 1;
console.log(`Random value between 1 and 10 is ${a}`);
Not A Bot
  • 2,474
  • 2
  • 16
  • 33

1 Answers1

2

The difference between -7 and -12 = 5.

First, change your code to give a random number between 0-4 (or 1-5) instead of 1-10.

After that, subtract 12 from the outcome.

Evert
  • 93,428
  • 18
  • 118
  • 189
  • Tried it like this on PlayCode and its returnig -5, very functional –  Mar 25 '21 at 06:45
  • `const a = Math.floor(Math.random() * (10 - 1)) + 1;let k=a-12; console.log(`Random value between 1 and 10 is ${a}`);console.log(k);` –  Mar 25 '21 at 06:45
  • I mean your code is returning values outside the expected range...-8,-9,-10,-11 –  Mar 25 '21 at 06:46
  • @CoderTimothy, yes you didn't follow all instructions. You are still looking for a number between 1 and 10 in the first step, not 0-4. Also, try some kindness for someone trying to help you. Your first comment is extremely rude. – Evert Mar 25 '21 at 06:49
  • i apologize if i sounded rude but i had of intentions of sounding so...Your code will work if i replace as you said , thanks –  Mar 25 '21 at 06:55
  • @CoderTimothy If you didn't intend it I misunderstood your intentions! I apologize for that =) good luck! – Evert Mar 25 '21 at 06:57