# How can I translate this to javascript? I have tried several times but it confuses me

**URL:** <https://discourse.processing.org/t/how-can-i-translate-this-to-javascript-i-have-tried-several-times-but-it-confuses-me/35942>\
**Category:** Beginners\
**Tags:** homework\
**Created:** [March 26, 2022, 1:36am UTC](https://discourse.processing.org/t/how-can-i-translate-this-to-javascript-i-have-tried-several-times-but-it-confuses-me/35942 "2022-03-26T01:36:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![VassKenn](https://avatars.discourse-cdn.com/v4/letter/v/a183cd/32.png) [@VassKenn](https://discourse.processing.org/u/VassKenn)\
**Post date:** [March 26, 2022, 1:36am UTC](https://discourse.processing.org/t/how-can-i-translate-this-to-javascript-i-have-tried-several-times-but-it-confuses-me/35942/1 "2022-03-26T01:36:32Z")

</div>

Write a method that prompts the user for 3 different integers and  
display on the screen on a single line, separated by commas. If one of the  
values is repeated, show only the repeated value.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [March 26, 2022, 2:23am UTC](https://discourse.processing.org/t/how-can-i-translate-this-to-javascript-i-have-tried-several-times-but-it-confuses-me/35942/2 "2022-03-26T02:23:59Z")

</div>

> [@VassKenn](#):
>
> Write a method that prompts the user for 3 different integers and…

- Use **[prompt()](https://developer.Mozilla.org/en-US/docs/Web/API/Window/prompt)** or [**createInput()**](https://p5js.org/reference/#/p5/createInput) w/ some message to prompt the user to enter the 3 numbers.
- Then apply [**trim()**](https://p5js.org/reference/#/p5/trim) followed by [**split()**](https://p5js.org/reference/#/p5/split) so it becomes an array.
- Force the array to have at max 3 number entries using [**min()**](https://p5js.org/reference/#/p5/min) like this:  
`array.length = min(3, array.length);`
- After that apply [**int()**](https://p5js.org/reference/#/p5/int) to remove any fractional parts from them.

> [@VassKenn](#):
>
> If one of the values is repeated, show only the repeated value.

I didn’t get this requirement part. Do you mean having unique values only?

If that’s so you can create a Set passing your array to it:

> **[Set() constructor - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/Set)**
>
> The Set() constructor creates Set objects.

Then use the spread `...` syntax to convert it back to array: `array = [...new Set(array)];`

> **[Spread syntax (...) - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax)**
>
> The spread (...) syntax allows an iterable, such as an array or string, to be expanded in places where zero or more arguments (for function calls) or elements (for array literals) are expected. In an object literal, the spread syntax enumerates the...
