Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 4) Colour My World Go to the https://www.npmjs.org web site and search f

ID: 3890809 • Letter: P

Question

Problem 4) Colour My World Go to the https://www.npmjs.org web site and search for an npm module called "colour". (note there is also a module called "color" but that is the wrong one.) Learn what service this module provides and look at the example code provided there to see how you can colour the text on your console screen. Install the module using the npm install colour command in your console window. You should notice a node _modules directory gets created as a result of the install. Now run the file colourTest.js in the demo code folder. The output likely looks like this: 5%8YSIMbid?4151617181920212223242526boldi talicunderlineinversesteiket hr. tegraygreyblackbluecyangreenmagentaredyellowrainbowzebrastripstr ne Day My Prince Hi Come

Explanation / Answer

It is unsafe to use for-each (for-in) for arrays. It is used for object properties. With arrays, this construct :
1. does not take care of ordering
2. gets properties of array element that it inherits from top order that may not be required to be exposed
3. is slow since it iterates over a lot of properties unlike plain for loop

Fix code by changing line 23 to
for(var i=0li<str.length;i++) {testStr1 += str[i];}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote