From 62c13cded5dbd989fc371290c11baf3048bae972 Mon Sep 17 00:00:00 2001 From: Karan <50290386+Sonawane-Karan26@users.noreply.github.com> Date: Wed, 24 Nov 2021 21:09:35 +0530 Subject: [PATCH] Exercise 8.4 --- Chapter 8/Exercise 8.4 | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Chapter 8/Exercise 8.4 diff --git a/Chapter 8/Exercise 8.4 b/Chapter 8/Exercise 8.4 new file mode 100644 index 0000000..49a9e55 --- /dev/null +++ b/Chapter 8/Exercise 8.4 @@ -0,0 +1,12 @@ +const val = "thIs will be capiTalized for each word"; +function wordsCaps(str) { + str = str.toLowerCase(); + const tempArr = []; + let words = str.split(" "); + words.forEach(word => { + let temp = word.slice(0, 1).toUpperCase() + word.slice(1); + tempArr.push(temp); + }); + return tempArr.join(" "); +} +console.log(wordsCaps(val));