Skip to content
This repository was archived by the owner on Oct 1, 2025. It is now read-only.

Commit 627fb6b

Browse files
committed
feat: Coding Challenge 4 of DS and Modern Operators Done
1 parent 2a350a0 commit 627fb6b

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

challenges/section09-challenge.js

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,69 @@ console.log(gameEvents);
204204
console.log(`An event happened, on average, every ${ 90 / gameEvents.size } minutes`);
205205

206206
for (let [key, value] of gameEvents)
207-
console.log(`[${ key <= 45 ? 'FIRST' : 'SECOND' } HALF] ${ key }: ${ value }`);
207+
console.log(`[${ key <= 45 ? 'FIRST' : 'SECOND' } HALF] ${ key }: ${ value }`);
208+
209+
// Coding Challenge 4
210+
211+
/*
212+
Write a program that receives a list of variable names written in underscore_case
213+
and convert them to camelCase.
214+
The input will come from a textarea inserted into the DOM (see code below to
215+
insert the elements), and conversion will happen when the button is pressed.
216+
Test data (pasted to textarea, including spaces):
217+
underscore_case
218+
first_name
219+
Some_Variable
220+
calculate_AGE
221+
delayed_departure
222+
Should produce this output (5 separate console.log outputs):
223+
underscoreCase ✅
224+
firstName ✅✅
225+
someVariable ✅✅✅
226+
calculateAge ✅✅✅✅
227+
delayedDeparture ✅✅✅✅✅
228+
229+
Hints:
230+
§ Remember which character defines a new line in the textarea 😉
231+
§ The solution only needs to work for a variable made out of 2 words, like a_b
232+
§ Start without worrying about the ✅. Tackle that only after you have the variable
233+
name conversion working 😉
234+
§ This challenge is difficult on purpose, so start watching the solution in case
235+
you're stuck. Then pause and continue!
236+
Afterwards, test with your own test data!
237+
GOOD LUCK 😀
238+
*/
239+
240+
document.body.append(document.createElement('textarea'));
241+
document.body.append(document.createElement('button'));
242+
243+
244+
const textArea = document.querySelector('textarea');
245+
const button = document.querySelector('button');
246+
247+
button.addEventListener('click', () =>
248+
{
249+
const params = textArea.value.split('\n');
250+
const modParams = [];
251+
252+
for (let param of params)
253+
{
254+
param = param.toLowerCase();
255+
256+
const words = param.split('_');
257+
const modWords = [];
258+
259+
modWords.push(words[0]);
260+
261+
for (let i = 1; i < words.length; i++)
262+
modWords.push(words[i][0].toUpperCase() + words[i].slice(1));
263+
264+
modParams.push(modWords.join(''));
265+
}
266+
267+
let msg = '';
268+
for (let i = 0; i < modParams.length; i++)
269+
msg = msg.concat(`${ modParams[i] } ${ '✅'.repeat(i + 1) }\n`);
270+
271+
console.log(msg);
272+
});

0 commit comments

Comments
 (0)