In this video, I'll show you how to solve a simple coding problem by reversing the order of words in a sentence. This #Codingame speed challenge is a great way to learn how to code in JavaScript. Whether you're new to programming or looking to improve your skills, this tutorial is perfect for you. Watch me code along and learn how to reverse the order of words in a sentence today! #learntocode #programming #javascript #codingtutorial"
Transcript:
Welcome to Programming University! Today we're building a phrase reversal tool. What it does is it takes any phrase, such as 'hello world,' and reverses the order of the words in the phrase.
To start, we add '.split' with a space at the end of the phrase. What this does is it converts the phrase 'hello world' from being a string into an array of different words. '.split' will break it up according to whatever is between those quotation marks, and we've put a space set so it's going to break up the phrase according to any spaces.
I've just quickly console.logged and you can see it says 'hello, world,' two items in general. We've created a for loop, which is going to count backwards through each word in the phrase array and add them to 'reverse.' 'Counter' equals 'phrase.length - 1,' starts at the index number of the last word in the array.
'Counter great or equal to 0' means that as long as our counter doesn't go below zero, it's going to keep counting down, and 'counter--' means countdown by one each time this piece of code is run. Now we just need to add the piece of code that it will run each time. Here it is: 'reverse.push(phrase[counter]).'
What this does is it pushes to the new 'reverse' array the word from 'phrase' which is at the position 'counter.' And obviously, 'counter' is starting at the end and counting backwards, meaning that it pushes the last word and the second-last word, and so on until it runs out of words.
Now the 'reverse' array has all of the words from the phrase but in backwards order ('world, hello'). We just need to join them together to create a new phrase ('world hello'). To do this, we've added '.join' with a space inside of the '.join' so that all the words are joined together with a space between them.
We've now completed our reversal tool, which can reverse any phrase. Like and follow them!"
On this page of the site you can watch the video online Learn JavaScript Coding: Reverse Phrase Program in 2 Minutes | New Coder Tutorial with a duration of hours minute second in good quality, which was uploaded by the user Quick Hacks Coding 28 February 2023, share the link with friends and acquaintances, this video has already been watched 60 times on youtube and it was liked by 0 viewers. Enjoy your viewing!