O'Reilly Forums: Ch. 7 Multiple Line Tweets Fix - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Ch. 7 Multiple Line Tweets Fix tweetshirt.js / splitIntoLines function

#1 User is offline   CanDaMan 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 07-December 12

Posted 13 February 2013 - 11:23 AM

I believe that the code for multiple line tweets should be revised as follows.

function splitIntoLines(str) {
var strs = new Array();
var space = str.indexOf(' ', 60);
strs[0] = str.substring(0, space);
strs[1] = str.substring(space+1);
if (strs[1].length > 60) {
space = strs[1].indexOf(' ', 60);
strs[2] = strs[1].substring(space+1);
strs[1] = strs[1].substring(0, space);
}
return strs;
}

// I believe that the last two strs[ #'s] should be reversed. Originally it was '1' then '2'.

// Sorry if this has been addressed elsewhere, I didn't see it.

This post has been edited by CanDaMan: 13 February 2013 - 11:23 AM

0

#2 User is offline   CanDaMan 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 07-December 12

Posted 15 February 2013 - 06:36 PM

Correct? Incorrect? (It seems to work!)

I couldn't figure out why it wasn't working, so I started changing the code (no luck).

There were no posts here on it (that I saw). Starting over seemed to be the way to go,

so I tried dissecting it line by line. I was near the end when I said 'Why are they doing that?'

'I wonder if I . . .' -Presto!-

Either way, I think I learned a lot in the process, I at least solidified it in my mind!

Was it posted elsewhere, and I missed it?
0

#3 User is offline   Beth Robson 

  • Veteran Member
  • PipPipPipPipPipPipPipPipPip
  • Group: O'Reilly Employee
  • Posts: 364
  • Joined: 17-September 08
  • Gender:Female
  • Location:Seattle, WA
  • Interests:I am interested in computer science, the Web, social media and the internet, Mac development, and adult learning.

Posted 18 February 2013 - 09:16 AM

Yes, that looks like a fix! Thanks :-)
Elisabeth Robson
Co-founder, WickedlySmart.com
Author: Head First JavaScript Programming, Head First HTML5 Programming, Head First HTML and CSS, Head First Design Patterns
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users