-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1strings.js
More file actions
27 lines (23 loc) · 950 Bytes
/
1strings.js
File metadata and controls
27 lines (23 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
let myString = "hello,this,is,a,difficult,to,read,sentence";
console.log(myString);
let stringLength = myString.length;
console.log(stringLength);
let myString_new = "hello " +"this "+ "is a " + "difficult " + "to read " + "sentence";
console.log(myString_new);
//alternative, better way to do it://
myString = myString.replace(/,/g, " ");
console.log(myString);
//note: the /g means to use 'global' scope. if you didn't put this in, only the hello is separated with a space//
let vehiclesList = ["motorbike", "caravan", "bike", "car", "bus"];
function vehiclee(){
let advertisement = "Amazing Joe's Garage, we service ";
for (i = 0; i < vehiclesList.length; i++) {
if (i == vehiclesList.length - 1) {
advertisement += "and " + vehiclesList[i] + "s.";
} else {
advertisement += vehiclesList[i] + "s, ";
}
}
return advertisement;
}
vehiclee();