Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function whatCentury(year)
- {
- let g
- let num
- let array = []
- let result
- let number =[]
- let x = array[0] + array[1] +array[2] +array[3]
- let y = array[0] + array[1]
- for(let x = 0; x < year.length; x++){
- g = parseInt(year[x])
- array.push(g)
- }
- if (x == y){
- number[0] = year[0]
- number[1] = year[1]
- num = number[0] + number [1]
- }else{
- number[0] = year[0]
- number[1] = year[1]
- num = year[0] + year[1]
- num = parseInt (num)
- num = num + 1
- number[0] = parseInt(number[0])
- number[1] = parseInt(number[1])
- }
- let letter
- if(num< 21){
- letter = "th"
- }
- if (num > 20){
- if (number[1] == 1){
- letter = "st"
- }
- if (number[1] == 2){
- letter = "nd"
- }
- if(number[1] == 3){
- letter = "rd"
- }
- }
- result = num + letter
- return result
- }
- /*Возвращает век введенного года. Ввод всегда будет строкой из 4 цифр, поэтому проверка не требуется.
- Примеры
- "1999" --> "20th"
- "2011" --> "21st"
- "2154" --> "22nd"
- "2259" --> "23rd"
- "1124" --> "12th"
- "2000" --> "20th"
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement