villa manja interior design

villa manja interior design

>> [music playing] >> speaker 1: all right, everyone. welcome to your last section with me. it's been quite the semester. i can't believe this is, like,week 12 or 11, something like that. but because it's our lastsection, we have lots of candy. and i'm going to try andprep you as well as i can for your quiz on wednesday. so probably not the best way to,like, end section with quiz review.


but we'll try and make it fun. and there's always candy. so hopefully, that'll make it better. >> your quiz is going to be prettymuch the same thing as quiz zero. it's going to be thesame format, same length. you'll be in rooms scatteredacross campus, because there are close to 900 of you, and we can'tall hold you in rooms like this. so be sure to look at all ofthe quiz one documentation online at cs50.harvard.edutonight or tomorrow night.


make sure you know where you'regoing, what you need to bring. really, you just need to bring yourselfand a pencil, and you should be fine. the questions will bevery much the same. there will probably be a couplemultiple choice, a couple short answer, some coding, maybe some true/false,matching sorts of things. so you shouldn't be toosurprised by the format. >> what can be surprising is thelength, which, in previous years, has been much longer. in my year, i don't have a single friendthat i remember finishing the exam.


there were like multiplepages left blank. so the length can bekind of disorienting just because in some years, it hasbeen much longer than quiz one. i have no idea what it'sgoing to be like this year, but it's something to be aware of. >> additionally, thedifficulty-- people tend to find quiz one much moredifficult than quiz zero. again, you know, ifyou're kind of walking out feeling a little uneasy becauseyou didn't do as well as you thought


you would or you feel like you didn'tdo as well as you did on quiz one, remember that there are probably alot of other people feeling that way. i was definitely one of those people. quiz one, like, threw me for a loop. and my friends have this greatpicture of them at jp licks kind of with these hugesundaes, being like, quiz one, and looking like they're in tears. >> so it's a general feeling. it's a tough test, it's a tough quiz.


obviously, if you come out and youfeel like you rocked it, great for you. but know that you're probably not--you are almost most definitely not alone if you walk out feeling like,eh, probably could have gotten better. it's tough. mm-hm. >> audience: how much is it worthin relation to [inaudible]? >> speaker 1: it's worth the same. yeah. but again, it's also going to beaffected by how the rest of the class


does, how your section does,how you've improved over time. grading is a little bit of a black box. so what the actual numberor percentage you get is not necessarily like directlycorrelated with the grade you're going to get. there's a lot offactors that go into it. >> so with that, we're going togo through some quiz review. i'm just going to run thislike last time for you guys. i have all the answersto quiz one of last year.


so if you guys want to pullthat up on your own computers, if you've taken this exambefore and you have questions, i was thinking we couldjust go through some of the more difficult ones on that. so we can talk about it, maybeget a little more insight into the intuition behind some ofthese questions, how to approach them. >> as well, like last time,i have a 100-slide deck that has basically allof the slides that i have prepared for previoussections since your last quiz-- i


have in this deck. so we can go throughpretty much anything that we've talked aboutbeforehand that maybe you want a little more clarification on. we could do that first. >> but otherwise, i'm superhappy just to kind of work through these problems with you. and i'm really here tofocus on what you guys think would be most important to focus on.


like, obviously, all ofthis stuff is important. especially as we go through quiz one,i'll definitely point out things like, oh, this might be somethingyou really want to know or you want to have on your cheat sheet. i'll be telling you thingsas we kind of go through. >> so on that note, are there any thingsthat you guys would like to go over? also, if i don't have it in my deck,we can pull up something on the web, or we can try and makeup an example on the fly. but any concepts that youguys are a little fuzzy on.


[? brian, ?] did you have-- >> audience: oh, is it cumulative? like, is the stuff on quizzero going to be on here? >> speaker 1: it's cumulative,but it's much more of an emphasis on thingssince your last quiz. so obviously, you guys havelearned about variables, and loops, and conditionals. and it's not like those justgo away, because they're obviously inherent to everythingelse that we've learned now.


>> there might be a questionon the sorts, or there might be a questionon different searches. or there might be a couplequestions on maybe something you having to do with compilingor different errors. but if you've looked atquiz one from last year, you'll notice that it isvery much focused on things that have happened since your last quiz. >> why is that door always locked? it really bothers me.


because i always try to go through it. >> so that's pretty muchhow the quiz will be. so are there any concepts thatyou guys would like to go over? or we can jump right intojust looking at quiz one from last year and kind of goingthrough practice questions there. we can also switch back and forth. this is not a one-time sort of thing. any questions? yes.


>> audience: could i ask aquestion about another-- >> speaker 1: another one? >> audience: this is from another year. >> speaker 1: yeah. we can also do another year. >> audience: ok. so on 2011. >> speaker 1: 2011. ooh, that was the year before me.


let me pull this up. >> audience: i think. >> speaker 1: this aspectratio is throwing me off. >> audience: 11 and 12. >> speaker 1: 11 and 12. ok. well, here, why don't we do this? you guys-- everyone just take a coupleof minutes to look through quizzes. and we'll compile a list.


and then we'll go through them. all right? while i get a bunchof this stuff set up. i'm just going to writethings down on paper. >> 2011, 11 and 12? i'm just going to change this display. that's better. this over. all right.


>> anyone else have any thatthey'd like to start with? also, forgot to say, if you want moreof a bunch of people talking at you and just giving you a crackcourse in the last six weeks, we are running a reviewsession from 7:00 to 8:30 tonight in northwestb103, which also happened last time, where it's going tobe me, hannah, daven, with gabe and rob kind of helping from thesidelines of just kind of throwing all the information that you mightwant to have on your cheat sheet, slash, know in general there.


audience: that's also online, right? speaker 1: it's also online. so you can also stay out of thisicky weather, go to your dorm, and live-stream it if you'd like. i'm sure a lot ofpeople-- i know i would be doing that if i were in your shoes. so why don't we start with--while you guys-- hopefully, you're looking through. if not, i might just start workingthrough different things on quiz one


from last year unless youhave specific questions. >> we'll start with thisquestion here about stacks. so does everyone rememberkind of what a stack is? how we tend to-- can anyone just giveme a general description of a stack? a type of data structure. so it's one of thedata structures that we expect you to be familiar with-- likestacks, arrays, queues, so forth. >> audience: like firstin, last out, something. >> speaker 1: it's first in, last out.


exactly. so a stack is exactlywhat we tend to think about when we thinkof a stack of things. so a stack of plates. the first plate you put downis going to be at the bottom, and it's going to be the lastone that you remove at the end. because they stack up. >> and you take the one out of the bottom,typically, things crash and break. so stacks you can think ofjust like a stack of plates.


or the example we always like to useis in the d halls, you have the trays, they're all stacked up,and you take from the top. so the last one in is the first one out. >> so in the case here, wesee we have-- i wonder if i can actually zoom in a little bit. so we have this struct here. right? so you have some struct that hassome int numbers of capacity. so what do we think that represents?


this is an array with size capacity. >> so this really representsour stack in general. our stack is really just anarray with some set number that is its max, that is, its capacity. and then we have some int size, whichwill track the size of our stack throughout the courseof when we're using it. ok? >> in this case right here, we say that ourstack size has been initialized to 0. so we have an empty stack right now.


and then we want to completethe implementation of pop such that it returns the int at the top. and then if it's empty,it returns negative 1. so i want you guys just to thinkabout what we might do there. what might be one of the firstthings we'd want to check? there's a great thing here. whenever it says-- if there's ever someif statement, like "if stack is empty," or "if this returns null," or"if this is whatever"-- sorry. >> audience: write an if statement.


>> speaker 1: right. you could write an if statement. and that's probably one of thefirst things you want to check. whenever they give youkind of like a corner case like this, that's typicallyone of the first things you're going to check in your code. >> also, something torecognize for the quiz is if you have an inefficient wayto do something, write it down. because we're not gradingyou on design, we're


grading you on correctness for quizzes. so even if you know that it's a superbad way to do something but it works, write it down, ok? >> literally, i've seen kids last year--if you look at last year's one, they're like, do the mario pyramid. and they literally just did "print,hash, print, hash, hash, print, hash, hash, hash." but it's correct. it does what we told it to,so you can't take points off.


if you're down to thewire, obviously, you want to get a more elegant solution, andthe more elegant solution will probably be less code, which means you probablyhave a higher chance of being right. but if you're like, you knowwhat, no, i don't have time, i know this is a solution,it's not the best, write it. and you can even write on theside, i know this is terrible, but i know it works. so just a heads-up. >> so obviously, first thingis this if statement.


so what do we think this ifstatement is going to be? and actually, let me openup my great sublime editor. i'm going to code this and thenshow you guys when it's done. so int pop. so if we have this intpop void-- so obviously, this is some function that takes innothing and returns an integer, right? so it's just going to talk aboutthis stack that we've created. >> so just translating this lastsentence, "if stack is empty, pop should return negative1," how might we do that?


so if what? how do we know that the stack is empty? it's just size equals 0. stack.size equals 0. also, i'm kind of writing blind here. so if i make any typos-- oh,also forgot to mention this. >> last week, i totally figured outwhat our problem was with javascript. don't capitalize iand d. you should only capitalize i and get element by id.


and that was the entire error. so if you guys go back andactually look through my code, if you just make everything alowercase d, "forget element by id," it will work. so as i promised, i was very close. i just capitalized somethingi wasn't supposed to, which i'm sure you guys had in your last pset. >> so if our size equals 0,what are we supposed to do? >> audience: return negative 1.


>> speaker 1: return negative 1. cool. so now what do we do? we want to pop something off. now this is the casewhere we have something. our size is greater than 1or greater than 0, right? we actually have something there. so what we want to do is wewant to return right here. we're going to say we wantto return top of stack.


>> so how might we do that? how do we return the top of the stack? remember, our stack isjust an array, right? it has some capacitythat we've given it. as we've put things on-- or actually,we're going to write "push" after this. if things are in there--maybe a picture will help. hm, i like big chalk better. >> so if-- and you can justthink of this as our stack. so this is 0, 1, 2.


i don't know why my boxesare getting smaller. but there. >> so this is some stackwith a capacity of 5. and let's say we have somethinghere and we have something here. so at this point, oursize is equal to what? 2. and if we want to popsomething off of it, that means we want to getrid of this right here. so how would we return this value?


>> audience: size minus 1. so size minus 1, or youcould do size minus minus. but we can't just do size. it's inside a struct, right? so stack.struct. or stack.size. that's our index right there. >> and then if we lookback at our struct here, we notice that toactually access the array,


we need to do stack.numbersto actually access that array. so that returns the top of the stack. >> but something that-- if you guys lookat the answer key, this is all they give you. so this is it. but i might argue that they'remiss-- ooh, not what i wanted. i might argue that they'remissing something, because-- yes. audience: decrease the size. speaker 1: right.


we need to decrease our size now. so what's tricky aboutthis is once you return something, your function'sgoing exit, right? so what we might do is actuallydecrease our size first. and then we can just do stack.size. >> we can just use stack.sizeas our index, couldn't we? because if stack.sizeis 2, we decrement it. and so it's 1, whichis our actual indice. once we get rid of this, we actuallyonly have one thing in our array.


so it does both. audience: [inaudible]? >> speaker 1: well, in this case,we just returned the element at the top that is at oursize that's at the top. but we haven't done anything to thesize after we removed that element. this hasn't changed our size yet. this does actuallyinherently change our size. >> but to make it a little clearer,you could do stack.size minus minus. for me, it makes it, i don't know,a little more clear that-- ah,


that you're actually changingthe size and returning it. the other way was fine, becauseyou were changing and returning at the same time. but this is just another way to writeit that i wanted to show you guys. does that make sense? stacks, i think, aremuch easier than queues. [laughs] did you have any specific questionsabout 11 and 12, or just-- >> audience: i think it was the stack.


>> speaker 1: the stack size? >> audience: yeah. >> speaker 1: gotcha. yeah, you could do it inone of these two ways. >> so now we have the other one. this is really weird, likenot having this on my screen. so if we look here, we now want tocomplete the implementation of push, which actually puts something, goesand inserts something into our queue, or into our stack.


>> so if we notice, wehave a couple of things. we have our great-- if all else,whenever we have one of these, you guys should at least get halfa point, because all you have to do is convert this into c. andthey give you half of it. so "if a stack is fullor it is negative, then push should return false." >> so we only want positiveintegers to be on our stack. and this is going to eitherreturn true or false. so we should [inaudible] bool.


so translating. >> audience: [inaudible]. >> speaker 1: oh, thanks. this is why i have you guys. int n. perfect. because we're puttingsomething on to our stack. we actually need some number. >> so just taking that last line thatthey gave us, our kind of corner cases,


what do you think we have here? obviously, we're going to have some if. so we said, if our stack isfull or if n is negative. so probably easiest to startwith, so if n is less than 0 or-- remember your niceand and or operators there. >> how would we check tosee if our stack is full? what happens? >> audience: size equal capacity. >> speaker 1: exactly.


and what do we want to do there? >> audience: return false. >> speaker 1: return false. so halfway there, right? at the very least, you guyswill have half of this. so let's think about this. >> so this is the stack we start with. we're trying to putsome element on here. >> we have a size that'sequal to 2 right now.


we have a capacity that equals to 5. and let's say we havesome n that's equal to 3. so we need to input 3 into this space. and we need to input it into index 2. >> so how might we do this? trying to assign-- wewant to access our array. so stack.numbers. but at what indice wouldwe want this to be? stack.size.


and we want that to equal n, right? speaker 1: i was actuallyjust looking at that. i think that is wrong. >> audience: don't you want thespace past the current size? >> speaker 1: well, if we look here,our size at this point is 2. we want it to go into index 2,because this is the top of our stack. so i would say that itshould be stack.size, and then you would increase stack.size. does everyone agree?


i think i agree with that. you guys can arguewith me if you'd like. or not argue, but we can discuss this. >> speaker 1: mm-hm, is where it'sopen because of zero indexing. so whereas in the first part,i thought they were wrong, and they were actually right, thispart, i actually think they were wrong. i would say you shoulddefinitely input it here. i think we all agreewe have a size of 2. that's exactly where wewant our new number to go.


so stack.numbers atstack.size should equal n. and then we wouldincrement the stack.size. ++. and then what do we want to do? there's one last thing we have todo if we successfully inserted this? return true. and now you're done. so i feel like it was the whole minusminus stack.size and stack.size ++ that messed things up.


ugh. i keep-- i have this knee-jerktendency to always hit control, s, because i neverwant to lose any of my work. but i don't need to do that now. so that was stack. >> is there anything? did you guys find anyother questions that you'd like to go over from previous quizzes? if not, we can kind of start talkingthrough quiz one from last year.


>> audience: for the firstpart, i didn't really understand how you deleted the number. isn't it still there? >> speaker 1: the number's still there. but what happens is that because you'vetold it that the top of your stack is here, when you go to add somethingonto the stack, it'll just replace it. >> audience: oh, ok. speaker 1: yeah. so it's like he forgot and it's theretype of thing even though it's there.


audience: [inaudible] or anything? speaker 1: no. because we're in anarray, you don't have to worry about-- you'll justoverride it when you need it. any other questions? if not, we're just goingto start working through. >> audience: well, this one is on the 2013,but just going through the sql stuff. speaker 1: sql? so this is 26 through 29.


audience: yeah. speaker 1: ok. lovely. let's pull those up. oh, look. did you guys enjoy the steveballmer talk, by the way? it was pretty hilarious, in my opinion. i love that every time i bring up cs50'swebsite during section, it's like, oh, watch section.


and i'm like, mm. >> audience: can we do it? >> speaker 1: we'll do it at the end. how's that? because i know you guyshave always wanted to. so we'll do it at the end. one questions. speaker 1: it'll be a meta section. audience: it's like 5 seconds.


audience: really? audience: it's like 20 seconds. [interposing voices] [laughter] speaker 1: i like thatyou've already done it, which is what makes me happier. 26. actually, we're just going tomirror this now, because i can't. this is annoying.


now i can see everything. >> so obviously, this should bring backgreat memories from [? csg ?] finance. half of you about have yours graded now. the other half i will get tovery, very soon, i promise. >> so we have some sql tablethat's accounts here. probably similar toyour guys' user tables. and we have some numberthat was a primary key and represents a12-digit account number. and balance is how much money they have.


and the default value is 100. and they give them $100 anytime they open an account. i wish my bank did that. >> so we want to complete the schema byspecifying next to number in balance the appropriate sql type. so what do you guys think would bekind of like your knee-jerk reaction for types for these two? >> audience: int. >> speaker 1: an int.


and then for a balance? decimal. so decimal's right. int is close. kind of the big thing is thisunderlined 12-digit account number. whenever we have somethingthat's larger than eight digits, they want you to use bigint, which i think is-- >> audience: is that just sql? >> speaker 1: it's the only time i've heardof it is sql-- like using a big int.


it's just to give you alittle more precision, making sure you're notoverflowing type thing. in all honesty, i think thisis definitely one of the ones where it's like, oh,it's meant for people who have a little more knowledge of sql. we never talked aboutbig ints in your pset. so it's kind of like i'm pretty sureif you put int, it was half credit. >> and as i said before, there are goingto be some questions that are just meant to trip you up, sothat not everyone gets 100.


because of course, thereare some people in cs50 who have been doing this for likeeight years, and you're like, what are you doing? but yeah. >> decimal for balance was the obvious one. and then big int for number just becauseof that, like, underlined 12-digit. whenever anything is in bold or it'sunderlined, like, pay attention to it. we're not doing that just because. >> so "suppose that the bank imposesa $20 monthly fee on all accounts.


with what query could the bankdeduct $20 from every account even if it results fromsome negative balances?" so let's start simple. we have four main commandsfor sql, which are? do you guys remember the fourbig ones that i told you? >> update, delete, select, and insert. got it. so what do we think mightbe most useful for this one? we are-- update.


so update, because we're lookingat accounts that already exist. >> so remember our generalsort of thing is update. and then what comes after update? we have some tablethat we're referencing. so if i pull up sublime again-- update. so this is a general format. so we have update table. and then what's the next thing we have? >> you can do where.


and then we have some qualifier here. and then what do we have next? we have some set-- somethingequal to something. blah equals blah. updated blah. so that's like the generalidea for some update. >> so let's start filling thisin with what it should be. so what table are we talking about? accounts.


and then in this case,what's really cool is are we talking about specificusers within our account, or are we talking about all users? we're talking about all users. so in that case, we can justdelete this where qualifier. the where is only when you wantto limit what you're changing. if you want to change the entiretable, you can just drop that. >> so now we're at our set part. what do we want to change?


>> audience: balance. >> speaker 1: balance. and we're going to-- how arewe going to change balance? we have a $20 fee, right? minus 20. and they said it's ok ifwe have negative balances. so in this case, you don't needto do any further error checking. that is literally all you have to do. cool?


>> so let's go through the next one. "with what sql query could thebank retrieve the account numbers of its richest customers withbalances greater than $1,000?" if your bank and your richest customersare just the ones with over $1,000, i feel like you'redoing something wrong. like, how does a bank survive on that? like, that interest, not quite enough. with this sort of thing, what doyou think, of our four functions, do you think we're going to use?


select. so we're selecting someidentifier from table. and then where condition. so as we go throughthese, i'm just going to give you guys a general refresheron the general format of all of these. >> so we're selecting some sortof [? thing. ?] in this case, this is going to betypically some column. so in our case, we have number, balance. in your guys' case, maybeit was id, name, password.


any of those columns, that'stypically what we're selecting. >> so in this case here, whichkind of column, what identifier are we pulling from our table? what does it ask us for? it asks us for our numbers, right? the account numbers. so remember, just number in this case. if you guys ever had the error, thatbright orange box would come up. and it was like, unexpectedrow in, like, whatever.


that's because you calledyour table wrong, right? so be sure that you arecalling the column correctly. >> so from table, our tableis called accounts. again, make sure you'rereferencing your table correctly. and then what's our condition here? what are we looking for? we want our rich people. so balance greater than 1,000. there you go.


that's your query. not too bad, right? >> so now for our last one. with that, we're breezing through. so now "with what query couldthe bank close, i.e., delete"-- don't you love how theyjust gave you delete-- "every account that has a balance of 0?" i think we can all agree we'reprobably going to be using delete. i'm welcome to take anydiscussion around that.


but i think it's pretty safe tosay that we could use delete. >> so we're going to delete someusers from table, where condition. so same sort of thing as select. so in this case-- oh, sorry. i should delete from. because delete willdelete the entire row. so we don't need to talk about whichspecific things about a user we're deleting. if we delete a user, we'redeleting everything about them.


>> so in this case, we just need tofill in our where and our condition. so our table is just our accountstable, as we've been doing. and then what is our condition here? >> speaker 1: balance equals 0. correct. all good. >> speaker 1: so deleteinherently deletes everything. so whereas with select, select takes incertain columns that you want returned. if you wanted everything abouta user returned, you use star.


star says, return to meeverything from this user. or if you put where star, thatmeans just give me everything. >> but delete inherently has that. so if you say, delete fromaccounts where balance equals 0, it's going to go through. and everywhere that balance isequal to 0, it inherently does that. it'll delete everything. the star is more for--with select or update, it's talking more about the individualfields corresponding to a user.


>> so when you do selectstar from table where id equals 1, that returns to youeverything about the user with id 1. if you were to do select numberor select id comma name from users where id equals 1, thatjust returns their number or their id and their name. >> so we use star in that case togive us everything about a user. and delete inherently does that. it doesn't just delete the id,or just the name, or whatever. yeah, no.


it just deletes the entire user. so we don't have to worryabout the star there. >> if you wanted to deleteeverything, you could do that, and this'll just drop everything. but typically, youdon't want to do that. but if you ever want to deleteeverything, you could do that. >> have you guys found any other questions? >> audience: could you do 26? >> speaker 1: 26 we just did.


audience: oh, 25, sorry. speaker 1: 25. 25. oh. they're doing javascript. oh, i can't believe it. i'm going to mess us up again, guys. we got this. we're going to make this work.


ah, jquery. fun. >> so we are going to complete theimplementation of the web page in such a way that if they visit,input their name, and submit the form, they have this great alertwindow that is going to appear. so anything with alerts, we know thatwe're going to have to use javascript. yay, javascript. and if they fail to input aname before submitting the form, no alert should appear.


so you can use jquery,but you don't have to. >> so i'm going to let you guys workon this just for a couple minutes. think about it. and then we will code it. slash i am going to try and think of thebest way to explain this answer to you. we'll get it set up. >> so we're just goingto walk through this, because i know jqueryis a little confusing. javascript.


it's a little out there. so what we're going to do is[inaudible] actually solved this problem with jquery. so if you remember,jquery is just a library that's just built on top of javascript. it's meant to make yourlife a little bit easier. >> i would definitely, ifyou have time, look over a little bit of thedocumentation for jquery. but it's very similar to javascript.


it's got similar paradigms, where youuse this dot operator to call functions on objects that you have. >> so what we have here is for jquery,you should always have this sort of wrapper, which is the$(document).ready(function) function in parentheses here. so this might be somethingyou want on your cheat sheet. because at the very least, you canhave the wrapper for your jquery. and it'll at least getyou part ways there. >> so in the same way that wetalked a lot about javascript,


and we would start by lookingat what we're trying to edit or what we're trying to change. and that would typically be thefirst thing that we'd put in. so in this case, if we go back to thishere and we look at our form here, we have this inputs,right, this id of inputs. and we know that basedon our question, we are either going to throwan error if this is empty, or we're going to putthis into an alert, right? so probably safe to say that we'regoing to be dealing with inputs here.


>> jquery is very similar in that if wethink back to css, anything with an id we look at with a hash. anything with class welooked at with a dot, right? so in the same way here, whatwe're talking about is inputs. we saw that inputs isan id within our form. so we're going to refer to it as such. inputs. >> so when in doubt, evenif you have nowhere, if you're really unsure about how toapproach this, a, have this wrapper.


so start there withthe wrapper for jquery. b, make sure that you knowwhat you are changing. and when in doubt,put that in something, and do dot, whatever you thinkyou should be doing with it. >> audience: what is the wrapper? >> speaker 1: the wrapperis this first line. so this says, wait untilmy document is ready. then start messing with things. so we know we're messing with inputs.


so we're like, ok, inputs is our form. that's our id. so that's what we'regoing to be looking for. and we want to see what happenswhen this form is submitted, right? >> so as we might think,we have some .submit. so .submit just says, ok, this formthat we've referenced with hash inputs, when it's submitted,execute something else. so we're going to have some function. notice we have anonymous functions here.


we have an anonymous function here. >> audience: will it always be .submit,or is it just because in the html, we made the button type submit? >> speaker 1: it should be .submit, becauseit's some form that we are submitting. because this .submit doesn't necessarilycorrespond to what the button is like to call. but the fact that it's aform that we're submitting. >> so notice anonymousfunction here that says-- audience: i don't reallyunderstand anonymous functions.


speaker 1: so anonymousfunctions, they're just functions that don't have a name. so instead of having some main functionthat calls-- we could say, if document ready, then we would call inputs. and then, when submitted, call--like, if so-and-so submitted, we'd call some other function. an anonymous functionjust doesn't have a name, and it will just executewithin these sorts of things. >> so in this case, what this saysis, when our document is ready,


execute this function. this function is composedof everything within here. and then the next layer in is, ok,when inputs is submitted, execute this. it's just a way of denotingwhat should be executed when. it's literally just afunction that doesn't have a name, so they tend tobe nested into each other, because you can't call them by name. literally, an anonymous functionis just a function without a name. that's it.


just a way to encapsulatedifferent things that we want executed at specific times. >> speaker 1: the vent? where? >> audience: in theparentheses after function? >> speaker 1: after functions. which one? >> audience: both. if you put, like, event, or ifyou put an argument in there,


would it be wrong? >> speaker 1: in this case, i supposeyou could put an argument in there. but because we don't need anargument, there shouldn't be. like, it's the whole,like, you should only have things that arenecessary sort of thing. in the same way that if we had anyfunction that has int main void-- like, with int main void, youcould do int arg v, whatever. but if you don't need those, youshouldn't have them in there. same thing.


emma, did you have a question? so what we have so far is when ourdocument's ready, execute this. now we're looking atwhen it's submitted. so now we actually have sortof the meat of our thing. so we need to get the value that theuser submitted, whether that be a name or empty. and then we need to either returnthis alert or throw an error. either way. >> so how do we declare avariable in javascript?


var. so let's say, var nameequals-- or actually, we'll do value since i think it's name. so we have some value here that wewant to pull from our inputs form. so in the same way thatwe kind of did inputs, can anyone tell me what wemight be calling within here if we wanted to getthe name from the form? and if we look back at our form here,we notice that we have an id of name. audience: [inaudible].


>> speaker 1: you don't haveto think of it as an array. you don't need to worry about that. so we just have some name. and then because javascript and thingsare weird, we can't just do "name." we actually have to callsome function that gives us, like, the value of that identifier. so that is just .val. >> speaker 1: ok. so with javascript, this sort ofthing right here just goes through.


and you could think of this as-- it'slike almost a getelementbyid, where getelementbyid would actuallyreturn the full thing to you. the $("#name") is just like,ok, i have it, i can access it, but if you actually want itto return the value to you-- >> audience: is it like a pointer? >> speaker 1: it's kind of like a pointer. you could think of it askind of like a pointer. like, it says, ok, iknow how to get there, but to actually get the value out ofit, you have to explicitly ask for it.


and unfortunately, obviously, we don'tdo too much with javascript and jquery. >> so it's going to come down to how muchyou guys-- what you happen to know, what you happen to have seen, and whatyou can kind of logically guess at. because some of these things, youcould probably get halfway there. but to get it completely right,i think this problem probably had one of the lowest scores. audience: like, for example,for [inaudible] inputs, why don't you have to put val there? speaker 1: for this one?


because this is kindof like, as we said, some pointer, and this is me referencingit and actually getting us the value. >> audience: whereas [inaudible]? >> speaker 1: for inputs,inputs is just some-- it's like we're justlooking at it as a whole, and this .submit tellsus what we need to know. jquery and javascript is weird. i know. i know, guys.


there's a reason i don'tdo web programming. just kidding. i haven't had enough exposure to it. >> audience: [inaudible] css. >> [laughter] >> speaker 1: ok, that's css. css is just, like, make things pretty,it's not like let's deal with data. there's a difference there. so now hopefully, this part-- also, fora problem like this, where you may not


know the syntax, you could be like,ok, you could have some var value and be like, assume igot the value correctly. and then you could probablywrite this next part. this next part will probablyseem much more easy, or it would make logicalsense to you guys. >> whereas what we've written so far,i know i would be like, umm, yeah, i don't know that on the quiz. you can totally write psuedocodeand then break into real code when you-- it's kind of like math.


if you've ever had somemulti-part problem where you don't know how toget past the first step, but everything elserelies on that first step, you just say, like, assume x equals 4. and then you run with it, right? >> you can do the same thing with code. so you could say, assumei got the value right. then do this next part here. because this part actuallyshould be pretty logical.


>> so we need to checkif our value is empty. or if it's some name,actually give an alert. so what might we want to check? we want to have some if. what do you think our if is going to be? we need to check to see if valueis-- if it's not an empty string. >> perfect. so if that's the case,what do we want to do? we want to throw some alert, right?


so it's just alert. and then whatever we want inside. so what are we supposedto have inside our alert? >> audience: "hello." >> speaker 1: comma. and then do you guysremember how to concatenate? >> audience: plus. >> speaker 1: plus. so we want to have plus.


and then we need another plusfor our exclamation point. otherwise, what might we want to do? we don't want to do anything, right? so we just return false. not what i want to do. >> and then these, ofcourse-- what's important is to remember to closeyour anonymous functions. so if you notice, we have somefunction here that ends here. so we need to close thisfirst one and add a semicolon.


and then this one here has todo with this anonymous function, so we close it there. that knee-jerk reaction of saving. audience: is there a reason that--just in all the examples in javascript that i've seen, we havethe first curly braces on the same line as the function? >> speaker 1: that's stylistic. and actually, if you take 61, wedo all our curly braces that way. huh?


>> audience: if we did do that onthe pset, is that bad for style? >> speaker 1: no. we have explicitly toldyou guys to do this. but actually, this is kindof the dominating convention in a lot of c classes andjavascript and jquery. so obviously, i'm sure--and actually, if i were to do this problem completelyblind without having looked at it, there is probably very fewways i would have gotten this. >> i might have been like, ok, maybe ineed to grab something that's an input.


and i think having theknowledge that, like, ok, if i want to get somethingfrom a form that has an id, i refer to it in this way,i'd probably get that. i might get this. but really, the only thing that i thinki would really get is this right here. >> so it's kind of important toknow, as with any difficult test, you kind of choose your battles, right? if you know that you're not going to getthat first part for jquery, as i said, assume that you have this valueand do what you can with it.


and if you have time, go backand try and fill in the pieces. but don't let a question likethis really bog you down. because what? this was one question onjquery out of the entire exam. so yes, it'd be great if you got it. >> audience: [inaudible] youare welcome to use jquery. speaker 1: you arewelcome to use jquery. audience: ok. [inaudible]. speaker 1: how would you not use it?


i would have to lookup all my javascript. it's actually much easier,i think, to use jquery, because jquery actually reduces theamount of javascript you write probably by, like, half. so our code would probably betwice as long without that. so if you recognize-- the biggestthing to take away from this problem are the patterns. if you're accessingsomething from a form, you're going to use quotes, hash,whatever you're trying to access.


if it's being submitted, you wantto use something like a .submit. you're probably going to usean anonymous function in there. if you actually need the value ofsomething, you're going to do quotes, hash, whatever that field is, .val. and recognizing patternslike that are going to be far more useful thanreally knowing the nitty gritty. >> audience: so if theuser submits their name and it runs through that statement, willit go down and return false after this? >> speaker 1: no, because the alert,you can think of it like a return.


so it'll exit. >> audience: could you[? place ?] the parentheses of submit, parentheses, something? >> speaker 1: i did, i believe. this one's closed right here. and then this one gets closed down here. >> audience: oh, there. >> speaker 1: obviously, little,little syntactic things like that, we'll probablyjust circle it and be like,


don't forget your parentheses. do we have another onethat we would like to do? did you guys get the binary tree one? do we want to go over that one? i feel like binary treesand doms should be points that you guys get pretty easily. i would not want youto lose points on that. >> let's do this dom here. i wish i had my surface so icould just draw on the screen.


that's what i used to do last year. so as i mentioned, we talkedabout dom, document object model. they're probably going to give yousome little bit of snippet like this and ask you to create a tree for it. and this just all has to dowith running through the tags. so let's try and do this. >> also, as per usual, if you guysdo these quizzes, as i highly recommend that you do as practice,any of them that you're like, i really don't get what'sgoing on here, just, of course,


send me an email with a question,and i will explain as best i can. >> we have some document, and we have html. so then we're just analysingthe tags here, right? so what do we see comes-- what arethe two subheadings under html? especially becausethey're indented properly? head and body. ah. so then let's start here with head. what's underneath head?


what's our next tag? title. and then within title, quiz. >> so literally, it's justwalking through the tags, ok? so then if we havebody, as we go through, body has three things within it, right? it's got three divs. every div gets its own little box. and what's in the first div?


[inaudible] and then the next one is middle,which i'm just going to abbreviate. and then the last one is bottom. >> so really, it's just walking through. and because we're going to giveyou html that is properly indented, you can literally just run throughand be like, ok, here is the html. so this is the outermostcorner, or furthest left, so that has to be its own thing. these are on the same indention.


>> so we know that head needs tobe at the same level as body, but underneath html. it's what we have here. head and body are siblings,but they're under html. and then we just go into each of these. so head has title, whichhas quiz, as we see here. and then in this case, we havebody, which has these three lines. so these are allsiblings all under body. so hopefully when you seesomething like this, you're like,


yes, i just get to draw a tree. it's gonna be great. so wanted to make sureyou guys knew that. >> so why don't we go to32 with our binary tree? because once you understand a binarysearch tree, it's really not that bad. so everett, can i erase-- imean, these are all online, too. so if you have any questions. >> lost a little space there, but it's ok. so binary search tree isjust a way to organize data


not in an array, wherethe root is always greater than the left child and the root isalways less than the right child. >> so we have this great search tree here. we have these numbers, 34,59, 20, 106, 36, and 52. and we need to organizethem in such a way such that the root is greaterthan everything on the left side and it is less thaneverything on the right side. and typically, what youwant to do is try and find something about in the middle.


with binary search trees, you might haveto play around a little bit with it. >> but in this case, let's justassume that we know this first one. so 36 is our first one here. typically, i would tryand choose something about in the middle that'llprobably yield the best results. so now we know that everything onthis side needs to be less than 36. but also, what you could see isthat we have two spots over here. so if we know that we need twonumbers that are less than the root, then you could just order theseand choose the third number.


>> so why don't we start with this side? so if we know that everything onthis side needs to be less than 36-- but if we look at this one,we know that this number has to be less than this number, right? because this number hereis on the right side. and remember, just as in our largertree, everything on the right needs to be larger than the root. in this way, we know thatwhatever is in this needs to be larger than whatever's here.


>> so we have two choicesfor these two bubbles. we have 32 and 34-- or sorry. 20 and 34. so how do you thinkwe might put these in? if this one has to bebigger than this one, that means we want tohave 20 here and 34 here. >> so in the same way, we lookat this kind of sub tree. and we say, ok, we have not 36. we have 106, 52, and 59.


in this case here, weknow that this one needs to have one thing that's greater thanit and one thing that is less than it. so if we put these in order, it's justabout finding that middle value again. so our middle value is 59. so then we say, ok, what's less than 59? well, that's 52. and what's greater than 59? well, that's 106. so it's just a bit like a puzzle.


it typically helps, especiallyin small trees like this, if you just order it, if youknow how many are on the left and how many are on theright, that can just allow you to choose whatshould be at your root. and then you can kindof work from there. 33? sure. so we want to create a nodeor a binary search tree. and let's look at what might be in it.


and i think this willactually be our last problem. >> this is like what we canthink of as a node, right? we have some value, and weknow that it will either have left and right children. binary search tree-- that meansthat it has, at most, two children. let's think about the way wedefined a linked list, right? >> we had some int thatrepresented the value. we had some pointer that representedwhat it was going to next. binary search tree is very similar.


we still have some value,n, that we give it, right? and then i drew these veryexplicitly with arrows, because they are effectively pointers. >> so n is typically what? it's some value. what do we typically designate it as? an int. so we have some int n, or int value,or whatever you'd like to call it. and then we have the leftchild and the right child.


and we know that what they'repoint-- what are they pointing to? they're pointing to other nodes, right? so how would we declare a node pointer? >> speaker 1: mm-hm. and we're going to havetwo of those, right? and then we can literallydo left for the left child and right for the right child. actually-- sorry. because we need struct.


>> so struct is because we haven'tfinished declaring a node yet. so node is within here. it's kind of like arecursive definition, right? so when we are withinthis definition, we haven't finished declaringnode as the structure, so we have to do structnode just to say, yes, we are in fact referringback to ourself type thing. that like once it'screated, it'll be fine. >> so how big do you guys think this is?


what's the size of this structure? 12. why? precisely. and in fact, one of thefirst questions one quiz one is about sizes, which is why i asked. >> we are going to end, because thedce will yell at me if we don't. but if you guys have any questions,of course, email me, let me know. you guys are going to rock it.


i'm super excited. you guys will be done asof wednesday, and then you'll get to work on your finalprojects, and it's going to be awesome. >> i will be here nextweek from 4:00 to 4:30 if you guys want to comepick up your quizzes. if you want to find me some other timeor just coordinate a different time, feel free to let me know. otherwise, this is our last section. so it was great to see you guys.


please take more candy. and good luck on your quiz.


Subscribe to receive free email updates: