Click here to Skip to main content
15,435,841 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
JavaScript



Question:

Using console.log, on three separate lines, print out the substrings for the following strings.

a. bla bla
b. "Melbourne is" in "Melbourne is great" (note the space!)
c. bla bla

Please help me with task b.
The task is to make a substring with the word/sentence
"Melbourne is" to: "Melbourne is great"

"Melbourne is".substring(0,12) );

How do i add the word "great" to the sentence?


I am new to coding.
English is not my native language.
Posted

If you aspire to be a developer then learn to use the tools that are there to help you. See http://www.w3schools.com/js/default.asp[^].
 
Share this answer
 
In JavaScript, this is done by the operator +.

It's function depends on the types of the operands. If both are strings, it returns concatenation, something you need. If only one of the operands is a string, another one is converted to a string by calling toString() on it and the result is then concatenated with another operand. If both are not strings, the operator does something else (number arithmetic :-)).

A type is a very non-trivial concept in JavaScript, very different from many other technologies:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures[^],
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof[^].

—SA
 
Share this answer
 
Comments
George Jonsson 4-Dec-15 3:28am     CRLF
I think the OP misunderstood the task, but I could be wrong. See Solution 3
Sergey Alexandrovich Kryukov 4-Dec-15 10:31am     CRLF
Add, take substring... Maybe it's better to stop responding to such "questions"... —SA
Quote:
Using console.log, on three separate lines, print out the substrings for the following strings.

a. bla bla
b. "Melbourne is" in "Melbourne is great" (note the space!)
c. bla bla

As I read the question it means that you need to extract the part "Melbourne is" from the string "Melbourne is great", not adding it.

(It could of course be a case of left out information, so I am completely wrong.)

As mentioned in Solution 1, W3Schools is a good start for beginners.
See especially JavaScript String Methods[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900