Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Problem 6. Word or Number
- //
- // Write a program that reads text from the console.
- // Check if this text is a number or a word.
- // If the text is a word print it reversed on the console.
- // If it is a number add 1 to it and print it.
- // The input is text on a single line (without intervals).
- // If the input is a word it won't contain any digits!
- // The output is like in the examples below.
- // Examples:
- // input output
- // good doog
- // TA AT
- // 32 33
- // 42.5 43.50
- // -1 0
- // let input = ['good'];
- let input = ['43.50'];
- let print = this.print || console.log;
- let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
- //Gets the text
- let text = gets();
- //Text converted to number
- let num = Number(text);
- //Create an empty string that will host the new created string
- let newText = '';
- //check if is not, not a number
- //if true: log the result(number) + 1
- if (!isNaN(num)) {
- num += +1
- console.log(num)
- } else {
- //creat reverse (decrementing) for loop and log out the result
- for (let i = text.length - 1; i >= 0; i--) {
- newText += text[i];
- }
- console.log(newText)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement