Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Help please?

I'm writing my very first piece of JavaScript so please forgive any rank beginner errors, I am a rank beginner so they're apt ;-)

When I get it right, it will take numbers and information input by the user and output a knitting pattern.

I'm stuck around lines 25 to 45 measure is returning properly, but hand, thumb and thumbBase are returning as undefined

Also on line 70 "stitchesPerFourInches/10*hand" is returning as Nan so I'm certain I've done something wrong there. Please ignore what I've commented out, those are things I haven't got to yet.

Help please?

// JavaScript Document
/* User input area for later use
var yourName = document.getElementById('name'),
    handCircumference = document.getElementById('handCirc'),
    thumbCircumference = document.getElementById('thumbCirc'),
    thumbBaseToIndex = document.getElementById('thumbBase'),
    stitchesPerFourInches = document.getElementById('gauge'),
    needleSize = document.getElementById('needles'),
    yarnUsed = document.getElementById('yarn'),
    cm = "",
    inches = "";
    */
//temporary variables for use now so I can figure out my errors
var yourName = "Sarah",
    handCircumference = 22,
    thumbCircumference = 23,
    thumbBaseToIndex = 24,
    stitchesPerFourInches = 25,
    needleSize = "4mm",
    yarnUsed = "Cleckheaton Country 8 ply",
    inches = true;

function pattern () {
if (inches === true) { var measure = "inches",
hand = function handInches (a, b){
    a*b;
    return handInches(handCircumference, 2.5)
    },
thumb = function thumbInches (a, b){
    a*b;
    return thumbInches(thumbCircumference, 2.5)
    },
thumbBase = function thumbToIndex (a, b){
    a*b;
    return thumbToIndex(thumbBaseToIndex, 2.5)
    };
} else {var measure = "cm",
hand = function handInches (){
    return handInches(handCircumference)
    },
thumb = function thumbInches (){
    return thumbInches(thumbCircumference)
    },
thumbBase = function thumbToIndex (){
    return thumbToIndex(thumbBaseToIndex)
    };
}

return yourName + "\'s Custom Fit Fingerless Mitts Pattern \n"+
"You can create more custom fit mitt patterns at http\:\/\/goo.gl\/4uIxfx\n" +
"\n" +
"Size\: " + "to fit " + handCircumference + " " + measure + " hand circumference \(excluding thumb\)\n" +
"\n" +
"Materials\n" +
"\n" +
"Needles\: A set of size " + needleSize + " double pointed needles and a set of DPNs one or two sizes smaller for the ribbing\n" +
"Yarn\: " + yarnUsed + "\n"+ 
"\n" +
"Tension\: " + stitchesPerFourInches + " sts per 10cm\/4\" over stocking stitch on " + needleSize + " needles\n" +
"\n" +
"Abbreviations\n" + 
"\n" +
"M1 = Make 1 stitch by putting your needle under the thread that lies between stitches, twist it (to avoid making a hole), and knit it.\n" +
"\n" +
"P2tog = Purl 2 stitches together.\n" +
"\n" +
"Pattern\n" +
"\n" +
"Using smaller needles, cast on " + 
parseFloat.stitchesPerFourInches/10*parseFloat.hand +
" sts, and join for knitting in the round. Place a marker at the beginning of the round. \n" +
"\n" +
"Work 5cm\/2\" k1, p1 rib.\n" +
"\n" +
"Change to larger needles and work 2.5cm\/1\" of stocking stitch \(knit every round\).\n" +
"\n" +
"Make thumb gusset as follows\:\n" +
"\n" +
"K1, m1, k1, m1, k to end of round\n" +
"\n" +
"Knit 1 round\n" +
"\n" +
"K1, m1, k3, m1, k to end of round\n" +
"\n" +
"Knit 1 round\n" +
"\n" +
"K1, m1, k5, m1, k to end of round\n" +
"\n" +
"Knit 1 round\n" +
"\n" +
//"Continue increasing in this manner \(working 2 more stitches between the m1's on every second round\) until you reach \"K1, m1, k" + odd thumb x (stitchesPerFourInches/10) + ", m1, k to end of round\n" +
//"Next round\: K1, put next " + round up to nearest odd number (stitchesPerFourInches/10) x thumb + "sts onto a holder, cast on 1 st, k to the end of the round.\n" +
"\n" +
//"Continue working rounds in stocking stitch for" + thumbBase + measure + "\n" + 
"\n" +
"Change to smaller needles and work 1.25cm\/\½\" in k1, p1 rib. Cast off neatly in rib.\n" +
"\n" +
"Thumb\n" +
"\n" +
"Using smaller needles work k1, p1 rib across the stitches you put on a holder, beginning with a purl stitch, then pick up 3sts at the top of the thumb \(where you cast on 1 st after finishing the thumb gusset\).\n" +
"\n" +
"Place a marker for the beginning of the round.\n" +
"\n" +
"Next round\: Work rib to the last 4sts, P2tog, k1, remove the end of round marker and purl the last stitch together with the 1st stitch of the next round. Replace the end of round marker.\n" +
"\n" +
"Work 1.25cm\/\½\ of k1, p1 rib \(beginning with a knit stitch this time!\), cast off loosely.\n" +
"\n" +
"Finishing\n" +
"\n" +
"Darn in all loose ends, wash and block.\n" +
"\n" +
"Copyright Sarah Bradberry June 2005. All rights reserved.\n" 
};

console.log (pattern());

2 Answers

I'm a javascript n00b so I'm not sure if this will help.

parseFloat is not used correctly (check out dochub.io/#javascript). I bypassed your function and just added the equation to a new var named handInches and basically took the equation you had in your function and it works.

 var handInches = handCircumference * 2.5,

then in your return I replaced what you had with this,

 parseFloat(stitchesPerFourInches) / 10 * parseFloat(handInches)

Thanks, that worked perfectly! Great link too, thanks