forked from KelvinMuriithi/html-css-js-recap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring-operations.js
More file actions
33 lines (30 loc) · 1.06 KB
/
string-operations.js
File metadata and controls
33 lines (30 loc) · 1.06 KB
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
let studentName = "John Doe"
let age =18
// interpolation operation
console.log(`Hello my name is ${studentName} and I am ${age} years old`)
// concatenation operation
console.log("Hello my name is " + studentName + " and I am " + age + " years old.")
// string manipulation operations using js methods
let upperCaseName = studentName.toUpperCase()
console.log(upperCaseName)
let lowerCaseName=studentName.toLowerCase()
console.log(lowerCaseName)
// getting the length of a string and checking if a string contains a specific word
let length = studentName.length
console.log(length)
let hasJohn = studentName.includes("z")
console.log(hasJohn)
// plucking a specific character from a string
let firstChararacter = studentName.charAt(0)
console.log(firstChararacter)
let lastCharacter = studentName.charAt(studentName.length - 1)
console.log(lastCharacter)
let fifthCharacter = studentName.charAt(4)
console.log(fifthCharacter)
age = 30
bruceAge = 23
if(age != bruceAge){
console.log("Bruce and I are not the same age")
}else{
console.log("Bruce and I are the same age")
}