Skip to content

Commit 7f909b1

Browse files
committed
complete challenge 4
1 parent 25da0e3 commit 7f909b1

File tree

8 files changed

+5998
-1386
lines changed

8 files changed

+5998
-1386
lines changed

09-Data-Structure-Modern-Operators-and-Strings/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,7 @@ planesInline(5); // There are 5 planes in line ✈️✈️✈️✈️✈️
917917
- `indexOf()`: Returns the position of the first occurrence of a substring.
918918
- `lastIndexOf()`: Returns the last occurrence of a substring in the string.
919919
- `slice()`: Returns a section or the index to the beginning of the specified portion of stringObj
920+
- `split()`:
920921
- `starsWith()`: Returns true if the sequence of elements of searchString converted to a String is the same as the corresponding elements of this object (converted to a String) starting at position. Otherwise returns false.
921922
- `endsWith()`: Returns true if the sequence of elements of searchString converted to a String is the same as the corresponding elements of this object (converted to a String) starting at endPosition – length(this). Otherwise returns false.
922923
- `padStart`: Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length. The padding is applied from the start (left) of the current string.

09-Data-Structure-Modern-Operators-and-Strings/challenge.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,3 +295,49 @@ console.log(stringBalanced("()"));
295295
console.log(stringBalanced("(()"));
296296
console.log(stringBalanced("))()))))()"));
297297
console.log(stringBalanced(")))))"));
298+
299+
// ----------------------------------------
300+
// Coding Challenge #4
301+
// ----------------------------------------
302+
303+
/*
304+
Write a program that receives a list of variable names written in underscore_case and covert them to camelCase.
305+
306+
The input will come from a textarea inserted into the DOM (see code below), and conversion will happen when the button is pressed.
307+
308+
THIS TEST DATA (pasted to textarea)
309+
underscore_case
310+
first_name
311+
Some_Variable
312+
calculate_AGE
313+
delayed_depature
314+
315+
Desired OUTPUT (5 seperate console.log() outputs)
316+
* underscoreCase ✅
317+
* firstName ✅✅
318+
* someVariable ✅✅✅
319+
* calculateAge ✅✅✅✅
320+
* delayedDepature ✅✅✅✅✅
321+
322+
HINT 1: Remember which character defines a new line in the textarea 🙂
323+
HINT 2: The solution only needs to work for a variable made out of 2 words, like a_b
324+
HINT 3: Start without worrying about the ✅. Tackle that only after you have the variable name conversion working. 🙂
325+
HINT 4: This challenge is difficult on purpose, so start watching the solution in case you're stuck. Then pause and continue!
326+
*/
327+
328+
document.body.append(document.createElement("textarea"));
329+
document.body.append(document.createElement("button"));
330+
331+
const btn = document.querySelector("button");
332+
btn.textContent = "Submit";
333+
334+
btn.addEventListener("click", function convertCase() {
335+
let text = document.querySelector("textarea");
336+
const rows = text.value.split("\n");
337+
338+
for (const [i, individualEl] of rows.entries()) {
339+
const [first, second] = individualEl.toLowerCase().trim().split("_");
340+
const result = first + second[0].toUpperCase() + second.slice(1);
341+
console.log(`${result.padEnd(20)} ${"✅".repeat(i + 1)}`);
342+
}
343+
});

css/main.css

Lines changed: 40 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

css/main.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<title>JavaScript Course</title>
1010
</head>
1111
<body>
12-
<h1>Console.log</h1>
13-
<script src="09-Data-Structure-Modern-Operators-and-Strings/script.js"></script>
12+
<script src="09-Data-Structure-Modern-Operators-and-Strings/challenge.js"></script>
1413
</body>
1514
</html>

0 commit comments

Comments
 (0)