Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > BOOK: Beginning JavaScript 5th Edition
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning JavaScript 5th Edition
This is the forum to discuss the Wrox book Beginning JavaScript, 5th Edition by Jeremy McPeak; 978-1-118-90333-9
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning JavaScript 5th Edition section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 1st, 2018, 07:05 AM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Jul 2018
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Cool Chapter 2 - incrementing now working as expected

In chapter 2 we have the following example:

Code:
myNumber = 1;
myVar = (myNumber ++ * 10 + 1);
In the book we are told the result for myVar should be 12, but after testing it a few times I got 11 each and every time.

How is this possible? Clearly, incrementing is not working as expected.
Reply With Quote
  #2 (permalink)  
Old July 7th, 2018, 03:37 PM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Jul 2018
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Bit of a mixup.

This seems to be a minor error, the code actually skips over the ++; operator entirely to get the desired result you can re-write this code with a simple change.

Code:
myNumber = 1;
myVar = (myNumber * 10 + 1);
myVar++;
This would yield the desired result. You can also place "++" on the Pre side instead of the Post side of the variable. (shown below)


Code:
myVar = (++myNumber * 10 + 1);
However this is interpreted as: 2 * 10 + 1 which is 21.

Hopefully this helps clear up any confusion.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
autoScale property not working as expected whiterainbow BOOK: Professional Outlook 2007 Programming ISBN: 978-0-470-04994-5 0 April 20th, 2011 07:49 AM
Chapter 10/Live Folder - UriMatcher not performing as expected. emanuel BOOK: Professional Android 2 Application Development 1 June 4th, 2010 05:52 PM
Dataset relations not working like expected panda869 C# 0 March 2nd, 2008 11:04 AM
Incrementing attribute value Pankaj C XSLT 4 October 31st, 2007 05:40 AM
Incrementing a value within a template Tre XSLT 1 March 21st, 2007 09:31 AM



All times are GMT -4. The time now is 06:18 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.