Learn Functional Programming by Building a Spreadsheet - Step 102

Tell us what’s happening:

I’ve tried looking through the forum, but there isn’t much information on this question… I’ve searched online and have been unsuccessful…I fear I’’ be stuck here forever. Please help

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()*(Math.max(nums.slice([0,2]))-Math.min(nums.slice([0,2]))))

}

// 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/131.0.0.0 Safari/537.36

Challenge Information:

Learn Functional Programming by Building a Spreadsheet - Step 102

slice doesn’t want an array, it needs one or more numbers as arguments

Math.max and Math.min also take a comma separated list of numbers, not an array

Hi. I’m sure one of the of the earlier projects created a random number between 2 numbers you can look at. As a beginner I suggest you look on the internet how to do this and have a go at trying to do this, then work out how to put that together into the property as a function.

See for example JavaScript Random

You can think of the 2 numbers as a min and max number.

i was reading a post about parameter destructuring, and i was under the impression the brackets are how you get a number rather than an array from the slice method…

destructuring doesn’t change what a method takes as arguments and what it returns

read about slice here

i sincerely don’t remember going through a project with this lesson… while i was reading the posts apparently there use to be a random color generator that utilized a random number generator between a range but that project wasn’t included in the course i’m doing…

Learn Basic Debugging by Building a Random Background Color Changer is the 4th project, you may not remember it, but it’s there

with the math.min, would it look something like Math.min(nums.slice(0),nums.slice(1))?

thank you for finding that for me… maybe it was just so short and long ago that I have no memory of it

slice returns an array, so you are passing to Math.min two arrays, while it needs numbers

you don’t need slice here

how do you access an element of an array at a certain index?

so nums[0],nums[1] inside the math.min and math.max? no slice anywhere?

you can use slice if you really want to, it’s unnecessary, as there is a simpler way to get a single element from an array

I figured it out, thank you for the help with my issue in the math.min and math.max !

Here are the hints:
Don’t use the full array as the parameter; you only need the first 2 elements. Use destructuring assignment to just use 2 elements of the array as parameters. Now you can just follow the instructions and get the results.