Binding, Functions and Control Flow - Reading Assignment

  1. code that produces a value is an expression
  2. bindings point from a variable to its current value
  3. the sum of all bindings is the environment.
  4. a function is code that is wrapped in a value.
  5. console.log()
  6. A side effect is any expression or function that displays or otherwise changes the string or value on the webpage. :slight_smile: thanks to @Bladeskiosity
  7. alert(“hello side effect”)
  8. controll flow is order that the programm gets executet
  9. conditional execution is used to direct the controll with conditional statements
  10. for example if , elseif , else
3 Likes

What is an expression?

  • Code built from variables, operators which produces a value.
    What is a binding?
  • variable assignment that points to values
    What is an environment?
    -A program’s collection of variables/bindings and the given values.
    What is a function?
    -Expression wrapped in a value which can be called (run) to perform.
    Give an example of a function.
    -Math.max(11,22);
    What is a side effect?
  • Expression or function which would change a value of a value or property on a webpage.
    Give an example of a function that produces a side effect and another function that produces a value.
  • prompt("… and we’re live ______");
    What is control flow?
    -Determines the execution order of code based on values or outcomes.
    What is conditional execution?
    -Values or actions that are driven by prompts from users.
    What kind of keyword do you need to use to invoke conditional execution?
    -if, else
1 Like
  1. An expression is a fragment of a code that produces a value
  2. A binding is a resource that enables you to catch and hold values.
  3. An environment is the colection of bindings you have at a given time
  4. A function is a piece of program wrapped in a value (that sort of values arte called arguments)
  5. An example of a function can be:
    alert(‘This course is awesome!!’);
  6. A side effect is the change that a statement result can generate on the next statement (inside of the same block or program)
  7. An example of a function that produces a side effect:
    alert(‘side effect’);
    An example of a function that produces a value:
    console.log(2+3);
  8. Control Flow is the way statements are executed by the program. They are always executed from left to right, from top to bottom.
  9. Conditional execution is a resource utilized when you want some code to be executed if a certain condition holds. It allows you to take diferent paths given diferent situations
  10. To invoke conditional execution I need to use the keyword if. if I have more than 2 diferent paths, I need to use the keyword if and the keyword else
1 Like

Is this an okay place to ask questions? If not, where do I go (to remain in the forum, per my understanding of Ivan’s request.) Rather than await an answer, I’ll pose my question. Answers from the community are, I suppose, optional; but do please direct me to the right place to ask things about reading and assignments if necessary.

The example says:

let theNumber = Number(prompt(“Pick a number”));
console.log("Your number is the square root of " +
theNumber * theNumber);

Not understanding the Number() function, I tried removing it:

let theNumber = prompt(“Pick a number”);
console.log("Your number is the square root of " +
theNumber * theNumber);

That worked fine, too. The text subsequently says the Number() is used to covert the value (string?) to a numeric, but JS seems to be so untyped (or just plain smart) that it does it automatically.

Could it be that the JS I’m using was released after EloquentJava was published, and the newer release guesses that strings of characters known to be digits with subsequent arithmetic operations should be converted when possible? If that’s NOT the reason, then what is?

BTW, if this IS the place for questions, why don’t I see others?

Trying something different, all answers are quoted from “eloquent Javascript”; as this for me has the most concise answers written in the shortest use of language ;-).

  1. An expression is “a fragment of code that produces a value”.
  2. Binding “creates a new function that will call the original function but with some of the arguments already fixed”
    3.The environment is a “collection of variables and their values that exist at a given time”.
    4.A function is " a piece of program wrapped in a value" and the value can “be ‘applied’ in order to run the wrapped program”
    5.Ex: Alert Function ; alert(“Good morning!”); wheras the funtion being the program telling what to do when applied, and the value being the string “Good morning!”
  3. Side effect is something that can “change the internal state of the machine in a way that will affect the statements that come after it”.
  4. So “showing a dialog box or printing text to the screen is a side effect” , in the example of Math.max, "it takes any number of number values and gives back the greatest: console.log(Math.max(2,4)); Result=. (Returns ‘4’)
  5. control flow is a prdictable execution of statements ie: top to bottom
  6. Conditional execution is “where we choose between two different routes based on a Boolean value”.
  7. if, if/else
1 Like

Hey afs,
I think you are in the right place for questions ect. Hey I just noticed perhaps did you accidentally put ‘let’ instead of ‘var’ the number as in :slight_smile:var theNumber = Number(prompt(“Pick a number”));
?

Thats the best I got right now, I’m still learning too,

Good luck.

YellowCake

So AFS,
If I’m understanding you correctly, you were having trouble with figuring what’s what with “theNumber” mumbo jumbo, I am going to attempt to explain in a different way.

So, the first part of the code is setting a ‘var’ called ‘theNumber’, it could just as easily be called ‘chicken’ if it makes it less confusing to first understand: as in, var chicken = 3

Now whenever you type ‘chicken’, you will get a response of ‘3’, because we created a var named chicken with an assigned value of 3.

So now we are simply creating a ‘var’ called ‘theNumber’ and saying it is equal to the next few things… so the ‘var’ is = prompt ------which is a function of it’s own (like a command)------- (“Pick a Number”) , this “Pick a Number”) is the ‘String’ or sentance we want to be prompted by the ‘prompt’ function…

Hope this gets you on the right track, and by me tring to answer your questions, although I’m not an expert, it helps me learn as well. At first I thought, I wasn’t going to participate in tring to help others because I am pretty new myself, but now I see the value as it helps me as well.

I hope I at least helped you a bit.

YellowCake

1 Like

I’m using the 3rd edition of Eloquent…, and the book uses let. Earlier reading made me think that if var isn’t technically deprecated, it’s still mostly o/o fashion (they said they’d explain later.)

Since I got your note, I tried it with var, both ways, and that’s cool too. I read on a bit, and I see they make a routine for what happens if you put in a non-numeric, and that’s fine. I’m happy to read on and see what they have to say.

But honestly, teaching materials that aren’t straightforward, or are ambiguous drive me ka-razy.

The introduction had this tidbit under typographic conventions:

function factorial(n) {
if (n == 0) {
return 1;
} else {
return factorial(n - 1) * n;
}
}

I didn’t drive myself to hard on this, since it was only about typographical conventions but – you know – I tried to understand the script anyway, but it was very hard. I tried to write it longhand, starting with n at 5 or something, but I got stuck owing to the recursion. Maybe if I start at 1 (the exit point) and work my way up to 5, I’ll understand it. My point is only that if you’re teaching a person to drive, you don’t give the general theory of relativity as an example of why GPS works, even though there will be GPS in the car. There are other ways to help a person get familiar with the environment.

1 Like

Ah, I see you’ve sent a second note. Alas, it doesn’t address the question. That question is:

Why Number(prompt(“Pick a number”));
Instead of prompt(“Pick a number”);

Either will yield correct results, whether used with let OR var. If, as they point out later, a non-numeric input has to be accounted for, then we can add the number() function later as part of an input error trap. But this is a section on control flow and, as such, I see no need to muddy the materials with extraneous things. Anyhow, we’ll soldier on. It’s early, and I’m still calibrating the degree to which I put faith in my learning materials.

1 Like

I get you, it sounds perhaps, at this point you know more than I do, hope you can help me when I’m stuck…Cheers.

1 Like

If that’s the case, you might be in trouble.

But I’m not worried; we’ll figure it out – much sooner than we could commit to memory the 48 preludes and fugues (which many who lack genius have done.)

1 Like
  1. An expression is a piece of code that creates a value
  2. A binding sets a value to another value
  3. The collection of bindings and their respective values at any given time is called an environment.
  4. A function is a program inside of a value
  5. prompt(“Enter Passcode”);
  6. When something is executed and changes the way the machine affects the statements after it.
  7. Non-Side Effect: 1; Side Effect: let ten = 10; ten + 10;
  8. Control flow is the way that javascript reads code, which is top to bottom.
  9. Conditional execution is when the program executes certain lines of code depending on the given condition.
  10. “if”
1 Like

expression.
a fragment of code tha produces value is called an expression.
1)Expression.
every value written literally such as 22 is an expression.
2)Bindings.
bindings is a java script tool which it uses to catch and hold values.
3)The environment.
a collection of bindings and their values that exist at a given time
is called an evironment.
4)Functions.
a function is a program wrapped in values, this values can be applied to
to run the wrapped program.
5)Example of functions.
an example is the console.log function, which prints out its argument to a
text output device. It is an expression that retrieves the log property from the
value held by the console binding.
6)Side effect.
showing a dialog box or writing text to the screen is called a side effect.
7)example of function that produces a value is
console.log(math.max(7,9)+305);.
8)Control flow.
control flow is the order in which individual statememnts, instructions, or
function calls of an emperative program are executed or evaluated.
9)Conditional execution.
it is the statemenent that holds the flow of executions depending on some condition.
example we want some code to be executed if and only if some certain conditions hold.
10)the keyword used for invoking conditional executions is the ‘if’ word.

1 Like

1- A fragment of code that produces a value
2 - Binding is tying up a value to a named variable so that it can be stored in memory and not disappear after use
3 - A collection of bindings and their respective values that exist at a given point in time
4 - A binding that contains a set of instructions
5 - console.log(value);
6 - It is what happens when a function is invoked. Examples could be a value being returned or a dialog box pop-up requesting user input
7 -
Side effect: prompt();
Value: Math.max(a,b);
8 - Control flow is used to adjust the order in which a program executes statements
9 - Executing different statements according to pre-established conditions
10 - if

1 Like
What is an expression?

An expression is a segment of code that produces a value.

What is a binding?

A binding is a variable that points to a value. This value could be produced by an expression.

What is an environment?

An environment is the entire collection of bindings and variables in use.

What is a function?

A function is a program segment that runs when invoked. Using the “( and )” after a value that is a function invokes the function.

Give an example of a function.

result = SafeMath.add(x,y);

In the above example, the add method/function is invoked from the SafeMath library. It takes two parameters, adds them together, and returns a result that is then pointed to by the result variable.

What is a side effect?

A side effect is any state change occurrence that is not a returned value from the result of an invoked function.

Give an example of a function that produces a side effect and another function that produces a value.

The console.log() function is an example of a function that has a side effect, outputting to the screen.

An example of a function that returns a value could be the Math.min() function. It returns the smallest single value out of the parameters that have been passed.

What is control flow?

Control flow is the order in which a program executes. A basic program starts with a linear flow. Control flow could be altered through the use of an if statement. This if statement would create a fork in the flow of a program.

What is conditional execution?

An example of conditional execution would be similar to the if statement example above. If statements can take an expression as a parameter and if it results in a true boolean value, the following code segment will run. If not, the code segment following the else keyword will run.

What kind of keyword do you need to use to invoke conditional execution?

Keywords used to invoke conditional statements include if and else.

1 Like
  1. An expression is a fragment of code that produces a value

  2. A binding let the program keep an internal state and remember things

  3. An environment is the collection of bindings and their values that exist at a given time

  4. A function is a piece of program wrapped in a value

  5. prompt function , console.log function

  6. a side effect is a “state being changed” in the program (showing a dialog box for example)
    7)Example of a function that produces value :
    let a = 1;
    let b = 2
    console.log(Math.min(a,b));
    –> 1
    Example of a function that gives a side effect
    prompt(“write your name”);

  7. control flow is the order the statements are executed (from top to bottom)

  8. Conditional execution is where the program takes the proper branch based on the situation at hand .

  9. if, else if, else

1 Like

What is an expression?
• An expression is piece of code that produces a value
What is a binding?
• A binding links a variable to a value.
What is an environment?
• An environment is the collection of bindings and their values.
What is a function?
• A Function is a chunk of code wrapped in a value
Give an example of a function.
• console.log(“This is technically a function”);
What is a side effect?
• A side effect happens when an expression changes something about the machine (usually something in memory), which will have an impact on code that runs later.
Give an example of a function that produces a side effect and another function that produces a value.
• Side Effect:
○ console.log(“This function has the side effect of writing to the browser console.”);
• Value
○ Math.max(2, 4);
§ //This function returns the integer value of 4
What is control flow?
• Control flow is the order in which lines of code are executed.
What is conditional execution?
• Conditional execution decides which lines of code will run next based on conditional logic.
What kind of keyword do you need to use to invoke conditional execution?

if, else, while, do, and for are keywords that can be used to invoke conditional execution.

1 Like

1.An expression is a fragment of code that produces a value.

2.A binding or variable is the way you assign,catch and hold values in Javascript.Its function to keep the internal program state.A binding is valid as long as its not changed by an expression or process.

3.An environment is a collection of bindings or variables and their values at any given time.

4.A function is a piece of program wrapped in a value.

5.An example of a function is fi: call the ‘prompt’ function which results in an action from the Javascript engine in the browser:this opens up a dialog box.

6.When a function produces an interaction with the user beyond the value it renders internally is called a side-effect.

7.Showing a dialog box or writing text to screen are examples of a side-effects of functions,whereas the real function only renders a value.
example value: value= x

8.The control flow is the order in which the program executes the functions in the script,usually from top to bottom as a story.

9.A conditional execution is only performed when certain circumstances in functions are met.

  1. with the help of the keywords ‘if’ and ‘else’.
1 Like

What is an expression? A fragment of code that produces a value

What is a binding? A binding, or variable, is used to store values

What is an environment? A collection of bindings and their values that exist at a given time.

What is a function? A function is a part of a program that has been assigned to a value.

Give an example of a function. alert(“Hello World”);

What is a side effect? Showing a dialog box or writing to the screen.

Give an example of a function that produces a side effect and another function that produces a value.

side effect: alert(“Hello World”);
value: Math.max(4,2);

What is control flow? The order in which the program executes

What is conditional execution? The flow of the program may change paths based on conditions set in the program.

What kind of keyword do you need to use to invoke conditional execution? if

1 Like
  1. What is an expression?
    A piece of code producing a value

  2. What is a binding?
    The assignment of a value to a variable

  3. What is an environment?
    The current state of the program / machine, as defined by its collection of variables and their values

  4. What is a function?
    A piece of program that produces / assigns values

  5. Give an example of a function.
    x = 1 + 2;

  6. What is a side effect?
    The effect that code has on the state of the machine if perceivable by the user

  7. Give an example of a function that produces a side effect and another function that produces a value.
    Side effect: console.log(“hello world!”);
    Value: y = 2+5;

  8. What is control flow?
    The order in which the program is executed. Typically this is top-down, left-right, unless interrupted or conditional

  9. What is conditional execution?
    When the execution path of code is influenced by decisions of the if-then type: IF x DO a, ELSE DO b

  10. What kind of keyword do you need to use to invoke conditional execution?
    If

1 Like