Advertisement
3vo

Problem 9. Play with Number, Boolean and String

3vo
Oct 25th, 2022
767
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Write a program that, depending on the user’s choice, inputs a number, boolean or string variable.
  2. // * If the variable is number, the program increases it by one. * If the variable is boolean,
  3. // the program swaps it with its counterpart. * If the variable is a string,
  4. // the program appends * at the end. * Print the result at the console. Use switch statement.
  5.  
  6. let input = ['1', '3'];
  7. let print = this.print || console.log;
  8. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  9.  
  10. let userChoice = +gets();
  11. let userInput = gets();
  12.  
  13. switch (userChoice) {
  14.     case 1:
  15.         print(`Please enter a number: ${userInput}`);
  16.         print(`${Number(userInput) + 1}`);
  17.  
  18.         break;
  19.     case 2:
  20.         print(`Please enter a boolean: ${userInput}`);
  21.         print(!userInput);
  22.         break;
  23.     case 3:
  24.         print(`Please enter a string: ${userInput}`);
  25.         print(`${userInput}*`);
  26.  
  27.         break;
  28.  
  29.     default:
  30.         break;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement