1. -A fragment of code that produces a value is called an expression
2. -Bindings is helpful for catching and holding values for future use
3. -The collection of bindings and their values are called an environment
4. A function is a piece of program wrapped in a value
-for example a dialogue box asking for a password
-executing a function is called invoking, calling or applying it
5. -in a browser environment a binding prompt holds a
Function that shows a little dialogue box asking for an input
6. -a side effect is a possible return output from a function - for example showig a dialouge box or showing text on the screen
7. -side effect example is : for example showing a dialogue box or showing text on the screen
-value example: the math.max funtion takes any amounts of a number of arguments and outputs the greatest as the value
8. -is the order of program execution is top to bottom
9. Conditional execution is executed with the "If" keyword in JS to execute if and only if certain conditions hold.
10. If, else
-
Expression is a fragment of code that produces a value.
-
Binding is a variable which gets & holds a place for values.
-
Environment is a collection of bindings and their values at a given time.
-
Function is a group of statements, (piece of program, block of code,âŚ) designed to perform a particular invoked task.
-
function myFunction (x1, x2) {
return x1 - x2;
}
6.Side effect is when hidden statement(s) affect the statements which will come later in a code, and by doing so makes changes.
a) function with side effect
def plusWithSideEffects(x, y) { alert(âThis is a side effectâ); return x + y; }
b) example of a function that produce a value is I think a function under my answer No. 5
- Control flow is an execution of statements in order.
- Conditional execution is made when a code has branches, when more paths of an execution are possible. Which execution will be done depends on a what conditions are met (or not).
10.if, else, âŚ
-
What is an expression?
A fragment of code that produces a value. Examples of expressions include a value that is written literally, an expression between parentheses, a binary operator applied to 2 expressions or a unary operator applied to one expression -
What is a binding?
A binding is the mechanism by which a program keeps (stores) (points to) a value -
What is an environment?
The collection of bindings and their values that exist at a given time -
What is a function?
A piece of program wrapped in a value -
Give an example of a function.
Console.log, prompt -
What is a side effect?
A side effect is a statement that affects the world. For example, it could display something to the screen or change the internal state in a way that will affect future statements. -
Give an example of a function that produces a side effect and another function that produces a value.
Console.log is an example of a function that produces a side effect; math.max is an example of a function that produces a value -
What is control flow?
The order in which individual statements, instructions, function calls of a program are executed or evaluated -
What is conditional execution?
Conditional execution means the program can take different branches or paths based on the current situation. This is made possible by conditional statements or expressions. -
What kind of keyword do you need to use to invoke conditional execution?
If, if else, if else if else,âŚ
- fragment of code that produces a value
- variable that points to a value
- collection of bindings and their values that exist at a given time
- piece of program wrapped in a value
- prompt(âEnter passcodeâ);
- changes in the internal state of the machine or changes the world
- prompt(âEnter passcodeâ); Math.max(2, 4);
- the order in which statements are executed
- a condition must be met for the subsequent statements to be executed
What is an expression? â A fragment of code that produces a value. An expression is kind of like a sentence fragment whereas a Javascript statement would be a full sentence. A program is a list of statements.
What is a binding? â Triggered by âletâ, âconstâ, and sometimes âvarâ, it allows us to catch and hold values. âConstâ will point at the same value as long as it lives.
What is an environment? â The collection of bindings and their values that exist at a given time.
What is a function? â A piece of program wrapped in a value. Values given to functions are called arguments.
Give an example of a function. â prompt(âEnter passcodeâ);
What is a side effect? â Showing a dialog box or writing text to a screen.
Give an example of a function that produces a side effect and another function that produces a value. â Side Effect: prompt(âEnter passcodeâ); Value: console.log(Math.max(2, 4));
What is control flow? â The order in which the statements are written and executed.
What is conditional execution? â Allows us to create a branching road in which the program takes the proper branch based on the situation at hand.
What kind of keyword do you need to use to invoke conditional execution? â âIfâ
What is an expression? An expression is any code that outputs a value when executed
What is a binding? A binding lets name something and then set it = to an expression. It holds onto that value unless changed.
What is an environment? An environment is all of the binding that are present when you open a program.
What is a function? A function is a a set of instructions for the computer to follow to get to a value.
Give an example of a function. (Math.max) this function outputs the highest of whatever values are included in the function.
What is a side effect? When you execute a program and something happens aside from the output you were looking for. Such as seeing something on a screen or a change in the program.
Give an example of a function that produces a side effect and another function that produces a value.
Console.log produces text in the console as a side effect and Math.min produces an intended value.
What is control flow? The way that blocks of code are structured with statements in a specific order to run the program.
What is conditional execution? When a program is executed only if certain conditions are met within the program.
What kind of keyword do you need to use to invoke conditional execution? if or else
An expression is a fragment of code that produces a value.
A binding (or variable) is something that catches or holds values.
An environment is a collection of bindings and their values that exist at a given point in time.
A function is a piece of programming that can be called or invoked to perform and action or a calculation.
Function can be native to javascript or user defined. An example of a native javascript function is Math.max() which can be fed any quantity of numbers and will return the largest one.
A side effect is an action which happens during execution of function code, such as opening a dialog box or displaying a value.
An example of a function that produces a side effect is Alert().
An example of a function that returns a value is Math.min().
Control flow is the order in which a program is executed. It may be linear or not.
Conditional execution is the altering of control flow by using an IF statement. IF True, execution may proceed down a particular path. IF False, execution may proceed down a different path.
The IF keyword is used to invoke conditional execution.
- Expression is part of the code that produces value.
- With binding we can catch and hold values needed in the code. Is defined by keyword âLetâ.
- Environment is collection of values and their bindings in a given time.
- Function is part of a program wrapped in a value.
- console.log, getelementbyid, getelementbyclassâŚ
- Side effects are pop-up boxes or text on the screen appearing due to the function being invoked.
- For example: prompt or console.log
- Control flow is order for executing the statements in the program.
- Conditional execution - program is executed only under certain conditions specified in the code.
- The keywords for conditional execution are âifâ, âelse ifâ, âelseâ.
Ans to Program Structure Chapter 2
1What is an expression?
A fragment of code that provides a âvalueâ is called and âEXPRESSIONâ.
Expressions can contain other other expressions.
A program is a list of expressions.
2 What is a binding?
Bindings are used to catch or hold values, by using a thing called âbindingâ or âvariablesâ.
3 What is an environment?
The collection of bindings plus their values, at a given time, is called the âenvironmentâ.
4 What is a function?
A function is a piece of program wrapped in a value.
A lot of values in the default environment have a function built in.
Executing a function is called: âinvokingâ, âcallingâ, or âapplyingâ it.
5 Give an example of a function.
A JavaScript function is a block of code designed to perform a particular task: a set of statements that performs a task or calculates a value.
var,
alert,
console.log
6 What is a side effect?
âside effectsâ is the product caused by an expression or statement.
It causes a change in the environment,such as, alert, prompt, function.
7 Give an example of a function that produces a side effect and another function that produces a value.
This function âprompt("Enter passcodeâ);â a side effect that produces a dialog box asking for a password.
8 What is control flow?
The control flow is the order in which the computer executes statements in a script.
If your program contains more than one statement, the statements are executed as if they are a story, from top to bottom.
9 What is conditional execution?
Not all programs go from âtopâ to âbottomâ. Some need to pursue more than one âpathâ.
The program takes the proper âbranchâ, based on the situation at the moment. This is called:âconditional executionâ.
10 What kind of keyword do you need to use to invoke conditional execution?
In JavaScript the âkeywordâ if invokes a conditional execution.
1:A fragment of code that produces a value
2:Stored values for later use
3: A collection of bindings at any given time
4:A function is a piece of program wrapped in a value
5: Console.WriteLine("Enter Password: ");
6: Console.log(âFunctionâ)
7:Writing text on the screen is a side effect
8: executing code from top to bottom left to right
9:executing code if one circumstance is true or false with the âifâ key word
10: IF
- An expression is
somethinga fragment of code that produces a value. - A binding is a way to hold a value for something, using the let, var, or const keywords, followed by a name that is followed by the = operator and a value.
- An environment is the set of bindings and their values that exist in a program.
- A function is a piece of program wrapped in a value.
- Function ex: prompt.
- A side-effect is a new result from executing a function.
- An example of a function that produces a side-effect is the alert function; one that produces a value is the Math.max function.
- A Control Flow is the âstoryâ that consecutive statements create.
- A piece of code that produces a value is an expression
- Binding is linking a variable with some value
- An environment is a collection of expression and its value
- A function is a value that consist of number of expression
- prompt(âEnter the passwordâ);
- Writing a piece of code which gives some results on the screen is side effect
- var a = 6
console.log(a) - the control of the program is sequentially which is from top to bottom
- The flow of program which does not follow a sequentially flow but rather uses branching or skipping or jumping of codes is called as a conditional execution
- " if "
1. What is an expression?
A fragment of code that produces a value is called an expression
2. What is a binding?
To catch and hold values, JavaScript provides a thing called a binding, or variable:
let No_of_Apples = 5 * 5;
3. What is an environment?
The collection of bindings and their values that exist at a given time is called the environment.
4. What is a function?
A function is a piece of program wrapped in a value. Such values can be applied in order to run the wrapped program.
5. Give an example of a function.
For example, in a browser environment, the binding prompt holds a function that shows a little dialog box asking for user input. It is used like this:
prompt(âEnter passcodeâ);
6. What is a side effect?
Showing a dialog box or writing text to the screen is a side effect
7. Give an example of a function that produces a side effect and another function that produces a value.
a)
console.log(Math.max(2, 4));
// â 4
b)
console.log(Math.min(2, 4) + 100);
// â 102
8. What is control flow?
When your program contains more than one statement, the statements are executed as if they are a story, from top to bottom
9. What is conditional execution?
Not all programs are straight roads. We may, for example, want to create a branching road, where the program takes the proper branch based on the situation at hand. This is called conditional execution
10. What kind of keyword do you need to use to invoke conditional execution?
Conditional execution is created with the if keyword in JavaScript. In the simple case, we want some code to be executed if, and only if, a certain condition holds
- What is an expression?
An expression is a part of code that produces a value. - What is a binding?
A binding is a chunk of memory that holds a value. - What is an environment?
An environment is a set of variables and values. - What is a function?
A function is a section of program that performs a specific task. - Give an example of a function.
Date() is a function that returns the current date time. - What is a side effect?
Output to screen/dialog box is a side effect. - Give an example of a function that produces a side effect and another function that produces a value.
Side effect: alert()
Function produce a value: Math.max(, ) - What is control flow?
Control flow is the sequence that the program being executed. - What is conditional execution?
Conditional execution is a control flow where program is executed when certain conditions are met - What kind of keyword do you need to use to invoke conditional execution?
if, else if, else
1. What is an expression?
Itâs a fragment of code that produces a value
2. What is a binding?
Also known as variable, a binding is something that allows to grasp/point to a value
3. What is an environment?
Itâs a collection of bindings and their values that exist at a given time, which provide ways to interact with the surrounding system
4. What is a function?
Itâs a piece of program wrapped in as a value, which can take or not arguments
5. Give an example of a function?
prompt(âEnter a name:â);
6. What is a side effect?
something that happens in the GUI as a result of a JavaScript expression
7. Give an example of a function that produces a side effect and another function that produces a value?
Side Effect: prompt("Enter passcodeâ);
producing a value: console.log(Math.max(2, 4));
8. What is Control Flow?
It is the order by which statements are executed
9. What is conditional execution?
It refers to a command that is only executed if a certain condition is true
10. What kind of keyword do you need to use to invoke conditional execution?
you need the âifâ keyword
What is an expression? Itâs a fragment of code (including a value that is written litterally)
What is a binding? also known as a variable, it is what allows you to catch and hold a value using an = sign.
What is an environment? a collection of binding and their values that exist at a given time
What is a function? a piece of program wrapped in a value
Give an example of a function: console.log(âhello worldâ)
What is a side effect? when a function creates a lasting change
Give an example of a function that produces a side effect and another function that produces a value. Side effect: alert(âThis is a pop upâ) Value: Math.max(3,8,2)
What is control flow? when a program has mutiple statements they are executed in a straight line or âtop to bottomâ
What is conditional execution? when you need the program to branch off in a certain direction dependant on the situation at hand, rather that simply running the statements top to bottom.
What kind of keyword do you need to use to invoke conditional execution? IF, ELSE
1- The expression is two or several values with an applied one or several operators to give us new value.
2- Binding is when you tag a value to certain variable or state to catch and hold the tagged value.
3- The environment is a collection of binding and their values that exist at a given time
4- a function is a piece of program or several expressions wrapped in a value and hired to returns to you with a new value and it can be called any time you need it.
5- Example:
function greet (name) {
return "Hello, " + name + "!";
}
greet ("World");
// "Hello, World!"
greet ("Ivan");
// "Hello, Ivan!"
6- the side effect is what you get something other then return other value
7- Example of Side Effect:
var class = {name: "IvanOnTech", date: 2018};
function renameclass(newName) {
class.name = newName;
console.log("Renamed!");
}
renameclass("SmartContractProgramming"); //Renamed!
class; // {name: "SmartContractProgramming", date:2018}
Example of not side effect:
var class = {name: "IvanOnTech", date:2018}
function renameClass(oldClass, newName) {
return {name: newName, date: oldClass.date}
}
var newClass = renameClass(class, "SmartContractProgramming");
newClass; // {name: "SmartContractProgramming", date:2018}
class; // {name: "IvanOnTech", date:2018}
8- Control flow is leading your code step by step to execute each statement individually one after another.
9- Conditional execution is how to execute you statement according to the conditions then what will be the result after than for example: (If) you get this class well (then) take the next one, (else) your money will be refunded and you will be out of the class.
10- (if) (else)
1.An expression is any value or combination of values and operators which produces new ones.
2.A binding is a piece of code that acts as a placeholder of the expression and the values it produces.
3.An environment is the sum of bindings and their values that exists at a given time.
4.A function is a program wrapped in a value.
- let greeting = âHello world !â;
console.log(greeting); <----- function
6.A side effect is the impact that the execution of an expression (function) has on the environment (program) or the system on which it resides.
-
let yourName = (prompt (âfill out your nameâ));
console.log(10%3);
8.the chronological order (top to bottom) in which the the statements in a program are executed.
9 execution of a statement(s) based on conditions that have to be met, rather than the chronological execution of
- If
What is an expression?
A construction that returns a value
What is a binding?
A value holder, variable
What is an environment?
The context where code excutes
What is a function?
A usualy smal program encapsulated under a name that returns a value
Give an example of a function.
function Square( var X ) { return x*x;}
What is a side effect?
Consequences of a function, like modifying something outside the scope of the function
Give an example of a function that produces a side effect and another function that produces a value.
-A function that logs something
-The square function
What is control flow?
The order in what instructions are executed
What is conditional execution?
Flow execution that depends on the value of variables
What kind of keyword do you need to use to invoke conditional execution?
IF THEN ELSE, SWITCH
1. What is an expression?
An expression is like a sentence of code that has a value as a result.
2. What is a binding?
The method used to attach a value to a certain name. It memorizes this value so it can be called upon later on. Used with var or better yet with let. A binding can always be changed in the same way.
3. What is an environment?
All the bindings and their values used in a program.
4. What is a function?
A function is like a little program wrapped in a value. By using them you output a side effect or a new value.
5. Give an example of a function.
prompt(âenter passcodeâ);
This function will open up a dialogue box asking for user input.
6. What is a side effect?
In the example above. The dialogue box is a side effect. It doesnât create a new value, itâs just the program wrapped up in the function.
7. Give an example of a function that produces a side effect and another function that produces a value.
Prompt(âEnter passwordâ);
This gives a side effect = dialogue box.
Math.max(2, 4);
This gives a new value = 4 as it searches for the greatest value amongst the numbers.
8. What is control flow?
This means the order of how and when statements are activated. Itâs basically like reading a book. i.e. Binding the number 6 to the name âsixâ. All code below this statement will have the option to use 6 as a value of six. Until we bind six to a different value.
9. What is conditional execution?
When a program runs it might need to make a choice. It does this by depending on the conditions the programmer gives it.
10. What kind of keyword do you need to use to invoke conditional execution?
If.
let theNumber = Number(prompt(âPick a numberâ));
if (!Number.isNaN(theNumber)) {
console.log("Your number is the square root of " +
theNumber * theNumber);
} else {
console.log(âHey. Why didnât you give me a number?â);
}
In this example. The user wil see a dialogue box that says pick a number. IF he picks a number a value will be displayed giving the square root of his number. Or ELSE he will get a value that says âHey. Why didnât you give me a number?â.