Solved

If/Else Statements Socket.io Client

Posted on 2013-12-14
1
239 Views
Last Modified: 2013-12-14
I have been trying to add an If/Else statement to my Socket.io client for a personal project I've been working on. The end goal is to create a Bitcoin ticker with 2 values (oldPrice and newPrice) sent from the server. I would like to be able to change the styling and bg color depending on the values.

This is what I have to far:

var socket = io.connect('http://localhost:1000');

socket.on('newPrice', function(data){
   var newPrice = data.value  
});

socket.on('oldPrice', function(data){
   var oldPrice = data.value    
});

Open in new window


I would like to add this:

if (newPrice < oldPrice) {

            }else if (newPrice > oldPrice) {

            }

Open in new window


Thanks!
0
Comment
Question by:hallowz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
ID: 39718633
Hi,
I think you have to generate the variables "globally" like
var socket = io.connect('http://localhost:1000');
var newPrice = 0, oldPrice = 0;

socket.on('newPrice', function(data){
   newPrice = data.value  
});

socket.on('oldPrice', function(data){
   oldPrice = data.value    
});

Open in new window


Your compare should then be like
if (newPrice < oldPrice) {

            }else {

            }

Open in new window


HTH
Rainer
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question