FAQ: Code Challenges: Intermediate JavaScript - squareNums()

Hey cirufly,

Thanks for your message. Are you on a career path?

Feels like we might be at similar levels on Javascript. If you want to connect on Discord give me a shout. I’ve only just worked out how to use it, but it’s quite good for getting a bit of community going.

If not, no problem and all the best with your coding!!

1 Like

Hey, I’m on full-Stack path, currently 14% and about to start the Mixed messages project. It would be really nice to share and learn with someone else.
Discord: Ciru#2203
Feel free to text me if you want.

I’m so confused… This is what I wrote and it wasn’t working:

const numbers = [2, 7, 9, 171, 52, 33, 14]
const toSquare = num => num * num

const squareNums = (arr) => { 

//prints undefined

This is the solution the exercise help gave me. Spoiler alert here! :warning:

const squareNums = arr => 

The only difference is the brackets… can anyone explain to me when should I use this sytax instead of mine here? I used the same syntax for the declineEverything exercise and it worked out fine, but here it should be written without the parethesis (arr) and brackets {} :confounded:

The return, undefined is a result of the squareNums function not having a return. Insert a ‘return’ at the front of the line,

return arr.map(...)

or alternatively, write the function the same way you did toSquare so it returns implicitly.

1 Like

interesting! thanks a lot!
This javaScript course has gotten confusing and extremely hard!

1 Like

It only gets harder if we try to learn too much in one session. Make it a habit to go back over every unit and redo exercises, review the learning narrative, read up on the topic (MDN is top notch) and play with the concepts in a sandbox such as REPL.it. Stick to the basics until you can do it in your sleep so you get the feeling of success and get your mind used to solving problems. Be sure you are 100% on early concepts before pressing too far forward. This is not a race. Build a strong foundation from the start. It takes time, review and practice to gain confidence.

Jargon and technical terms tend to come out of every corner which only adds to the confusion. Keep the documentation readily at hand and read it multiple times. Eventually this will be walk in the park, but only if you put in the work and time.

1 Like

Thanks for the tip! I was thinking about that, that it would be a good idea to work on hundreds of exercises before moving on. The MDN documentation sometimes is confusing to me, I know is a great resource but I often have to google things out :stuck_out_tongue:
I was never good at math mostly because of my lack of will! (as one teacher once put it :rofl:)

1 Like

what is this REPL thing? I googled it but I read something about Python and not javaScript

www. repl.it

Register (it’s free) and then ‘Start new REPL’, choosing ‘JavaScript’ as the language. This will open up a blank sandbox with an editor and a console. Write your code in the editor then Run it. The editor autosaves so your work will never be lost.

The name of the site is a play on the acronym. REPL is a common term that describes how computers actually work. They are always waiting for a next instruction.

Read -> Evaluate -> Print -> Loop

This will appear in many introductory computer courses.

Try out this:
const squareNums = numbers => numbers.map(toSquare);

Sometimes simplicity is the key