Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

If/Else Statements Socket.io Client

Posted on 2013-12-14
1
Medium Priority
?
241 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 1500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

722 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