Square at Alternate Indices
Given an array
Sample Input 1
[ 1, 2, 3, 4, 5 ]
Sample Output 1
[ 1, 2, 9, 4, 25 ]
Sample Input 2
[ 2, 4 ]
Sample Output 2
[ 4, 4 ]
Filter Unique Characters
Given a string
myString as an input, write a JS program to find the unique characters from the myString.
Quick Tip
You can use the array method indexOf().
Sample Input 1
Was it a cat I saw?
Sample Output 1
[
'W', 'a', 's', ' ',
'i', 't', 'c', 'I',
'w', '?'
]
Sample Input 2
I did, did I?
Sample Output 2
[ 'I', ' ', 'd', 'i', ',', '?' ]
String Starts or Ends with given String
Given an array
stringsArray of strings, and startString, endString as inputs, write a JS program to filter the strings in stringsArray starting with startString or ending with endString.
Quick Tip
You can use the array method filter() and logical operator OR ( || ).
Sample Input 1
['teacher', 'friend', 'cricket', 'farmer', 'rose', 'talent', 'trainer']
t
r
Sample Output 1
[ 'teacher', 'farmer', 'talent', 'trainer' ]
Sample Input 2
['dream', 'player', 'read', 'write', 'trend']
p
d
Sample Output 2
[ 'player', 'read', 'trend' ]
String Slicing
Given two strings
Sample Input 1
JavaScript
S
Sample Output 1
Script
Sample Input 2
Language
air
Sample Output 2
Language
Split and Replace
Given three strings
inputString, separator and replaceString as inputs. Write a JS program to split the
inputString with the given separator and replace strings in the resultant array with the replaceString whose length is greater than 7.
Quick Tip
Sample Input 1
JavaScript-is-amazing
-
Programming
Sample Output 1
Programming is amazing
Mobile
You are given an incomplete
Mobile class.A Mobile object created using the
Mobile class should have the properties like brand, ram, battery, isOnCall, and song.Implement the
Mobile class to initialize the mentioned properties and add the following methods,
Method:
charging
Description: When this method is called, it should set the value of the battery to 100, if the battery is already 100 then log "Mobile Fully Charged" and call removeCharging
method:
removeCharging
Description:
It should log "Please remove charging"
method:
playMusic
Description:
It should log a text with the song, as shown in the sample output.
method:
stopMusic
Description:
It should log "Music Stopped"
method:
makeCall
Description:
When this method is called, it should set the value of the isOnCall to true and log "Calling ..."
method:
endCall
Description:
When this method is called, it should log "No ongoing call to end" if isOnCall is false, else log "Call Ended" and set the value of the isOnCall to false
0 <=
battery <= 100
sample input
Apple
2 GB
90
Waka Waka
false
sample output
Mobile charged 90%
Mobile charged 100%
Playing Waka Waka song
Music stopped
No ongoing call to end
Calling...
Call Ended
Mobile
You are given an incomplete
Mobile class.A Mobile object created using the
Mobile class should have the properties like brand, ram, battery, isOnCall, and song.Implement the
Mobile class to initialize the mentioned properties and add the following methods,
MethodDescriptionchargingWhen this method is called, it should set the value of the battery to 100, if the battery is already 100 then log "Mobile Fully Charged" and call removeChargingremoveChargingIt should log "Please remove charging"playMusicIt should log a text with the song, as shown in the sample outputstopMusicIt should log "Music Stopped"makeCallWhen this method is called, it should set the value of the isOnCall to true and log "Calling ..."endCallWhen this method is called, it should log "No ongoing call to end" if isOnCall is false, else log "Call Ended" and set the value of the isOnCall to false
0 <=
battery <= 100
Write a program that will ask the user to enter a number less than 256 and print out the value of the
number expressed in binary.
Allison takes a trip to a “Cent Store” where all items cost less than one dollar and she purchases one
item. Ask for the cost of the item in cents. Remember that the cost will be less than one dollar.
Display the minimum number of coins needed to make change for Allison’s purchase from one dollar.
Also display the number of each type of coin. (Possible coins are pennies, nickels, dimes, and
quarters.)
The class Object defines an equals() method to compare objects.
Specify the advantages and disadvantages of using this method and suggest an alternative for equality