fork download
  1. // Javascript Shell にて実行
  2. function check_color(color) {
  3. color = color.toLowerCase();
  4.  
  5. if (color.length !=3 && color.length !=6) {
  6. // ブラウザで実行する場合は console.log
  7. print("ERROR length : " + color.length);
  8. return false;
  9. }
  10.  
  11. if (isNaN(parseInt(color, 16))) {
  12. // ブラウザで実行する場合は console.log
  13. print("ERROR isNaN : " + color);
  14. return false;
  15. }
  16.  
  17. var _hex = parseInt(color, 16).toString(16).toLowerCase();
  18. while(_hex.length < color.length) {
  19. _hex = "0" + _hex;
  20. }
  21.  
  22. if (_hex != color) {
  23. // ブラウザで実行する場合は console.log
  24. print("ERROR NOT EQ : " + color);
  25. return false;
  26. }
  27. // ブラウザで実行する場合は console.log
  28. print("OK : " + color);
  29. return true;
  30. }
  31.  
  32. check_color("12"); // length error
  33. check_color("1234"); // length error
  34. check_color("12345"); // length error
  35. check_color("KKKKKK"); // 16進数ではない
  36. check_color("AKKKKK"); // 16進数ではない
  37. check_color("000000"); // 正常
  38. check_color("00FF00"); // 正常
  39.  
  40.  
  41.  
Success #stdin #stdout 0s 105856KB
stdin
Standard input is empty
stdout
ERROR length : 2
ERROR length : 4
ERROR length : 5
ERROR isNaN  : kkkkkk
ERROR NOT EQ : akkkkk
OK : 000000
OK : 00ff00