Training JS #1: create your first JS function and print "Hello World!"
Description:
In JavaScript, your code is running in a function, let us step by step complete your first JS function.
Look at this example:
--------keyword "function"
| ----your function name
| | ---if needed, some arguments will appear in parentheses
| | |
function myfunc(){ ---------your function code will starting with "{"
//you should type your code here
}----------------------------ending with "}"
If we want to print some to the screen, maybe we can use Document.write()
in the web, or use alert()
pop your message, but Codewars did not support these methods, we should use console.log()
in your function. see this example:
function printWordToScreen(){
var somewords="This is an example."
console.log(somewords)
}
If we run this function, This is an example.
will be seen on the screen. As you see, console.log()
is an useful method. You will use it a lot!
Task
Please refer to two example above and write your first JS function.
mission 1:
use keyword function
to define your function, function name should be helloWorld
(don't forget the () and {}
)
mission 2:
use keyword var
(or let
or const
) to define a variable str
, value of str
should be a string: "Hello World!"
(don't forget the =
).
mission 3:
type the console.log()
in the next line (don't forget to put the str
in the parentheses).
When you have finished the work, click "Run Tests" to see if your code is working properly.
In the end, click "Submit" to submit your code pass this kata.
Series
( ↑↑↑ Click the link above can get my newest kata list, Please add it to your favorites)
- #1: create your first JS function helloWorld
- #2: Basic data types--Number
- #3: Basic data types--String
- #4: Basic data types--Array
- #5: Basic data types--Object
- #6: Basic data types--Boolean and conditional statements if..else
- #7: if..else and ternary operator
- #8: Conditional statement--switch
- #9: loop statement --while and do..while
- #10: loop statement --for
- #11: loop statement --break,continue
- #12: loop statement --for..in and for..of
- #13: Number object and its properties
- #14: Methods of Number object--toString() and toLocaleString()
- #15: Methods of Number object--toFixed(), toExponential() and toPrecision()
- #16: Methods of String object--slice(), substring() and substr()
- #17: Methods of String object--indexOf(), lastIndexOf() and search()
- #18: Methods of String object--concat() split() and its good friend join()
- #19: Methods of String object--toUpperCase() toLowerCase() and replace()
- #20: Methods of String object--charAt() charCodeAt() and fromCharCode()
- #21: Methods of String object--trim() and the string template
- #22: Unlock new skills--Arrow function,spread operator and deconstruction
- #23: methods of arrayObject---push(), pop(), shift() and unshift()
- #24: methods of arrayObject---splice() and slice()
- #25: methods of arrayObject---reverse() and sort()
- #26: methods of arrayObject---map()
- #27: methods of arrayObject---filter()
- #28: methods of arrayObject---every() and some()
- #29: methods of arrayObject---concat() and join()
- #30: methods of arrayObject---reduce() and reduceRight()
- #31: methods of arrayObject---isArray() indexOf() and toString()
- #32: methods of Math---round() ceil() and floor()
- #33: methods of Math---max() min() and abs()
- #34: methods of Math---pow() sqrt() and cbrt()
- #35: methods of Math---log() and its family
- #36: methods of Math---kata author's lover:random()
- #37: Unlock new weapon---RegExp Object
- #38: Regular Expression--"^","$", "." and test()
- #39: Regular Expression--"?", "*", "+" and "{}"
- #40: Regular Expression--"|", "[]" and "()"
- #41: Regular Expression--""
- #42: Regular Expression--(?:), (?=) and (?!)
Similar Kata:
Stats:
Created | Apr 26, 2016 |
Published | Apr 26, 2016 |
Warriors Trained | 58104 |
Total Skips | 5259 |
Total Code Submissions | 162562 |
Total Times Completed | 39884 |
JavaScript Completions | 39724 |
CoffeeScript Completions | 69 |
Total Stars | 713 |
% of votes with a positive feedback rating | 89% of 4264 |
Total "Very Satisfied" Votes | 3486 |
Total "Somewhat Satisfied" Votes | 589 |
Total "Not Satisfied" Votes | 189 |