forked from ironhack-labs/lab-js-strings-cardio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
93 lines (68 loc) · 3.13 KB
/
index.js
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*******************************************
Iteration 1 | Find index of a character
*******************************************/
// Write code that prints out to the console the index of the character “j” in
const string1 = "My favorite dessert is jello";
// Your code here...
console.log(string1.indexOf('j'))
/*******************************************
Iteration 2 | Concatenate Characters
*******************************************/
// Make a new string with the text "COOL" by using only the characters available in the provided string and the bracket notation
const string2 = "ABCDEFGHJKLO";
const newString2 = string2.charAt(2) +
string2.charAt(string2.length -1)+
string2.charAt(string2.length -1)+
string2.charAt(string2.length -2)
console.log(newString2)
/*****************************************************
Iteration 3 | Repeat a String and Concatenate
*****************************************************/
// Using the method .repeat() and the provided string, print out the text "NaNaNaNa Batman!" in the console.
const string3 = "Na";
const newString3 = string3.repeat(3)
const batman = " Batman!"
console.log(newString3 + batman)
/*******************************************
Iteration 4 | Fruite Slice
*******************************************/
// Using the string method .slice(), access and print to the console the name of your favorite fruit from a given string
// Your code here...
const fruit = "banana apple mango orange lemon kiwi watermelon grapes pear pineapple";
console.log(fruit.slice(7,13))
//otro metodo
const favFruit = fruit.split(" ")
console.log(favFruit[1])
/***************************************************
Iteration 5 | Check If Strings Include a Word
***************************************************/
// Using the string method .include(), check if the below strings with funny newspaper headlines include the word "oxygen".
// If a string includes the word "oxygen" print to the console message "The string includes the word 'oxygen'",
// else print the message "The string does not include the word 'oxygen'".
const funnyHeadline1 = "Breathing oxygen linked to staying alive";
const funnyHeadline2 = "Students Cook & Serve Grandparents";
// Check the first headline
// Your code here ...
if (funnyHeadline1.includes("oxygen")){
console.log("The string includes the word oxygen")
} else {
console.log("The string does not include the word oxygen")
}
// Check the second headline
// Your code here ...
if (funnyHeadline2.includes("oxygen")){
console.log("The string includes the word oxygen")
} else {
console.log("The string does not include the word oxygen")
}
/*******************************************
Iteration 6 | String Length
*******************************************/
// Using console.log() print to the console the length of the string and the last character in the string.
const string4 = "zEAWrTC9EgtxmK9w1";
// a) Print the string length
// Your code here ...
console.log(string4.length)
// b) Print the last character in the string
// Your code here ...
console.log(string4.charAt(string4.length-1))