-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateYourFirstJSFunctionAndPrintHelloWorld.js
46 lines (31 loc) · 1.57 KB
/
createYourFirstJSFunctionAndPrintHelloWorld.js
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
35
36
37
38
39
40
41
42
43
44
45
46
/*
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.
*/
function helloWorld() {
var str = 'Hello World!';
console.log(str);
}