Learn Functional Programming by Building a Spreadsheet - Step 102

Tell us what’s happening:

can someone explain to me this random function because i have tried

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

const spreadsheetFunctions = {
  sum,
  average,
  median,
  even: nums => nums.filter(isEven),
  someeven: nums => nums.some(isEven),
  everyeven: nums => nums.every(isEven),
  firsttwo: nums => nums.slice(0, 2),
  lasttwo: nums => nums.slice(-2),
  has2: nums => nums.includes(2),
  increment: nums => nums.map(num => num + 1),
 // random: nums => Math.floor(Math.random() * num[1]) + num[0],//here is the problem
},

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0

Challenge Information:

Learn Functional Programming by Building a Spreadsheet - Step 102

Hi. The random function should generate a random number from 2 numbers in the array. As it should work with any 2 numbers passed to the function (in the parameters) just put placeholders for the 2 numbers there for now. Bear in mind the 2 placeholders are in an array - what additional brackets are required for the placeholders in the parameter?

Your calculation for calculating the random whole number needs a bit of work after the *. Have a look online for calculating a random whole number from 2 numbers in javascript.

Here’s an example of the syntax used to generate a random number in a specific range of numbers:

function getRandomInt(min, max) {
   return Math.floor(Math.random() * (max - min) + min);
}