8 kyu

Training JS #1: create your first JS function and print "Hello World!"

39,724 of 39,884myjinxin2015

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)

Fundamentals
Tutorials

Stats:

CreatedApr 26, 2016
PublishedApr 26, 2016
Warriors Trained58104
Total Skips5259
Total Code Submissions162562
Total Times Completed39884
JavaScript Completions39724
CoffeeScript Completions69
Total Stars713
% of votes with a positive feedback rating89% of 4264
Total "Very Satisfied" Votes3486
Total "Somewhat Satisfied" Votes589
Total "Not Satisfied" Votes189
Ad
Contributors
  • myjinxin2015 Avatar
  • Javatlacati Avatar
  • donaldsebleung Avatar
  • Chrono79 Avatar
  • kazk Avatar
  • hobovsky Avatar
  • __eloise__ Avatar
Ad