The browser storage localStorage is not available. Either your browser does not support it or you have disabled it or the maximum memory size is exceeded. Without localStorage your solutions will not be stored.
Strings
We have seen that a variable is a container for a value. A value can be a text like
You can work with strings. For example, they can be concatenated. This is done with the
'Hello world!'
.
Values have a type. The type of 'Hello world!'
is string. You can use single or double quotes.
'Hello world!'
is the same string as "Hello world!"
.You can work with strings. For example, they can be concatenated. This is done with the
+
sign.
'Java' + 'Script'
results in the string 'JavaScript'
.
The following function appends ' is great!'
to the passed parameter and returns the result:
function praise(name) {
return name + ' is great!';
}
praise('JavaScript')
will return 'JavaScript is great!'
.Exercise
Write a function
Example:
greet
having one parameter and returning 'Hello <parameter>!'
.Example:
greet('Ada')
should return 'Hello Ada!'
and greet('Grace')
should return
'Hello Grace!'
.
+ Hint
function greet(name) {
return ...
}
+ Solution
function greet(name) {
return 'Hello ' + name + '!';
}