File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 1+ // upper converts lowercase sting to upper case
2+ // input is 1 string i.e. str
3+ const upper = ( str ) => {
4+ // check that inputs are string
5+ if ( typeof str !== "string" ) {
6+ return "Not string(s)" ;
7+ }
8+
9+ var convertedString = "" ;
10+
11+ for ( let i = 0 ; i < str . length ; i ++ ) {
12+ if ( str . charCodeAt ( i ) >= 97 && str . charCodeAt ( i ) <= 122 ) {
13+ convertedString =
14+ convertedString + String . fromCharCode ( 65 + str . charCodeAt ( i ) - 97 ) ;
15+ continue ;
16+ }
17+ convertedString = convertedString + str . charAt ( i ) ;
18+ }
19+
20+ return convertedString ;
21+ } ;
22+
23+ console . log ( upper ( "abcd" ) ) ; // should print ABCD
24+ console . log ( upper ( "abcd1" ) ) ; // should print ABCD1
25+ console . log ( upper ( "*abcd" ) ) ; // *ABCD
26+ console . log ( upper ( "aBs" ) ) ; // should print ABS
You can’t perform that action at this time.
0 commit comments