Update 20_day_writing_clean_codes.md

Change `implicit` to `explicit` and  `camelCase` notion to `PascalCase`. Change implementation of  the `showDateTime` function.
pull/188/head
Chety 4 years ago committed by GitHub
parent 07143be3b7
commit fb31cd1e9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -137,13 +137,13 @@ const vegetables = ['Tomato', 'Potato', 'Cabbage', 'Onion', 'Carrot']
#### Functions #### Functions
By now you are very familiar function declaration, expression function, arrow function and anonymous function. In this challenge we tend to use arrow function instead of other functions. Arrow function is not a replacement for other functions. In addition, arrow functions and function declarations are not exactly the same. So you should know when to use and when not. I will cover the difference in detail in other sections. We will use explicit return instead of implicit return if the function is one liner By now you are very familiar function declaration, expression function, arrow function and anonymous function. In this challenge we tend to use arrow function instead of other functions. Arrow function is not a replacement for other functions. In addition, arrow functions and function declarations are not exactly the same. So you should know when to use and when not. I will cover the difference in detail in other sections. We will use implicit return instead of explicit return if the function is one liner
```js ```js
// function which prints full name of a person // function which returns full name of a person
const printFullName = (firstName, lastName) => firstName + ' ' + lastName const printFullName = (firstName, lastName) => `${firstName} ${lastName}`
// function which calculate a square of a number // function which calculates square of a number
const square = (n) => n * n const square = (n) => n * n
// a function which generate random hexa colors // a function which generate random hexa colors
@ -160,23 +160,8 @@ const hexaColor = () => {
// a function which shows date and time // a function which shows date and time
const showDateTime = () => { const showDateTime = () => {
const now = new Date() //or you can pass any locales you want instead of 'de'
const year = now.getFullYear() return new Date().toLocaleString("de");
const month = now.getMonth() + 1
const date = now.getDate()
let hours = now.getHours()
let minutes = now.getMinutes()
if (hours < 10) {
hours = '0' + hours
}
if (minutes < 10) {
minutes = '0' + minutes
}
const dateMonthYear = date + '.' + month + '.' + year
const time = hours + ':' + minutes
const fullTime = dateMonthYear + ' ' + time
return fullTime
} }
``` ```
@ -329,7 +314,7 @@ isRaining
#### Classes #### Classes
We declare class with CamelCase which starts with capital letter. We declare class with PascalCase which every word starts with a capital letter.
```js ```js
// syntax // syntax

Loading…
Cancel
Save