Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. var aaa = "0"; // Eu recebo essa variável como string (não dá para mudar o tipo)
  2.  
  3. console.log(typeof(aaa)); // String
  4. console.log(Number(aaa)); // NaN ===> Não deveria ser número 0?
  5. console.log(parseInt(aaa)); // NaN ===> Não deveria ser número 0?
  6.  
  7. // Isso sempre dá FALSE
  8. aaa = "1";
  9. if (aaa)
  10. console.log('true');
  11. else
  12. console.log('false');
  13.  
  14. // Isso sempre dá FALSE também
  15. aaa = "1";
  16. if (Number(aaa))
  17. console.log('true');
  18. else
  19. console.log('false');
  20.  
  21. <head>
  22. <title>TESTE</title>
  23. <link rel="stylesheet" href="/stylesheets/style.css">
  24. <link rel="stylesheet" href="/stylesheets/bootstrap.min.css">
  25. <script src="/socket.io/socket.io.js"> </script>
  26. <script>
  27. var socket = io.connect();
  28.  
  29. function changeState(state) {
  30. if (state == 1) {
  31. socket.emit('changeState', '{"state":1}');
  32. document.getElementById("outputStatus").innerHTML = "Status: ON";
  33. } else {
  34. socket.emit('changeState', '{"state":0}');
  35. document.getElementById("outputStatus").innerHTML = "Status: OFF";
  36. }
  37. }
  38.  
  39.  
  40. socket.on('sensorsUpdate', function (data) {
  41. var reading = JSON.parse(data);
  42. document.getElementById("IO_opened").innerHTML = reading.IO_opened;
  43. document.getElementById("IO_closed").innerHTML = reading.IO_closed;
  44.  
  45. if (reading.IO_opened {
  46. console.log('ABRIR');
  47. document.getElementById("IO_opened").className = "exibe";
  48. document.getElementById("IO_closed").className = "n_exibe";
  49. } else if (reading.IO_closed) {
  50. console.log('FECHAR');
  51. document.getElementById("IO_opened").className = "n_exibe";
  52. document.getElementById("IO_closed").className = "exibe";
  53. } else {
  54. console.log('Open = ' + reading.IO_opened + ' Close = ' + reading.IO_closed);
  55. document.getElementById("IO_opened").className = "n_exibe";
  56. document.getElementById("IO_closed").className = "n_exibe";
  57. }
  58. });
  59. </script>
  60. </head>
  61.  
  62. head
  63. title= title
  64. link(rel='stylesheet', href='/stylesheets/style.css')
  65. link(rel='stylesheet', href='/stylesheets/bootstrap.min.css')
  66. script(src='/socket.io/socket.io.js')
  67. include ../public/javascripts/sensorStatus.js //<<<<<====== Include do javascript
  68. body
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement