-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJSBasicPractice
34 lines (26 loc) · 1022 Bytes
/
JSBasicPractice
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
Q1. Write a function that takes a string as argument. The string contains the substring 'is'. Return the index of 'is'.
Ans. function myFunction(a) {
return a.indexOf('is');
}
Q2. Write a function that takes a string (a) as argument. Get the first 3 characters of a. Return the result
Ans. function myFunction(str) {
return str.slice(-3);
}
Q3. Write a function that takes a string as argument. Extract the last 3 characters from the string. Return the result
Ans. function myFunction(a) {
return a.slice(0, 3);
}
Q.Write a function that takes a string (a) as argument. Extract the first half a. Return the result
Ans. function myFunction(a) {
return a.slice(0, a.length / 2);
}
Q. Write a function that takes a string (a) as argument. Remove the last 3 characters of a. Return the result
Ans. function myFunction(a)
{
return a.slice(0, -3);
}
Q.Write a function that takes two numbers (a and b) as argument. Return b percent of a
Ans. function myFunction(a, b)
{
return a*(b/100);
}