Solved

If/Else Statements Socket.io Client

Posted on 2013-12-14
1
233 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
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now