https://www.codewars.com/kata/571ec274b1c8d4a61c0000c8
Codewars - Achieve mastery through coding practice and developer mentorship
A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!
www.codewars.com
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.
코드
//refer to the example and write your first JS function
function helloWorld(){
let str = "Hello World!";
console.log(str);
}
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] Keep up the hoop (8 kyu) / JavaScript (0) | 2023.03.02 |
---|---|
[Codewars] Double Char (8 kyu) / JavaScript (0) | 2023.03.01 |
[Codewars] Sum of a sequence (7 kyu) / JavaScript (0) | 2023.02.27 |
[Codewars] Snail (4 kyu) / JavaScript (0) | 2023.02.26 |
[Codewars] DNA to RNA Conversion (8 kyu) / JavaScript (0) | 2023.02.25 |
댓글