GLASGOW_CLASS_5_OMER_ALI_WEEK_1 - #176
Conversation
alastair87
left a comment
There was a problem hiding this comment.
Good work on parts A through G, though you should try and have a look at I through L. I can arrange a time to look at some of these with you if that would help.
| @@ -1 +1 @@ | |||
| console.log("Hello world"); | |||
| console.log("Hello World. I just started learning JavaScript!"); | |||
| // Start by creating a variable `greeting` | ||
|
|
||
| let greeting = "Hello"; | ||
| console.log(greeting); |
There was a problem hiding this comment.
You have declared and used the variable correctly however we also want you to print it three times. You could do this using a for loop as we have looked at for repeating code in class.
| } else { | ||
| message = true; | ||
| } | ||
|
|
There was a problem hiding this comment.
It's really good to try out different things like you've done here as it definitely helps with understanding them better!! However, if you do this you can also put it in a separate file just in case it interferes with the assigned task.
|
|
||
|
|
||
| if (messageChoice == 0) { | ||
| message = "This is a string"; |
There was a problem hiding this comment.
If you have a variable like messageChoice where you know what the type should be (this is true most of the time) it's good practice to use a strict equality check which means the === operator as opposed to ==. What this means is that the computer will check that not only do your variables / values represent the same 'soft value', but they also have the same type.
For example 0 == "0" is true, even though the left-hand value is a number and the right-hand value is a string. However 0 === "0" is false, since the values are not the same type.
|
|
||
| console.log(` | ||
| ${message} | ||
| ${messageType}`); |
There was a problem hiding this comment.
Excellent. Good to try out string interpolation as a way of outputting variables.
|
|
||
| greeting = greetingStart + MY_NAME; | ||
|
|
||
| console.log(greeting); |
| " and my name is " + | ||
| NAME_LENGTH + | ||
| " characters long"; | ||
| console.log(message); |
| let message = ""; | ||
|
|
||
| // Calculate total number of students | ||
| totalStudentsAndMentors = numberOfStudents + numberOfMentors; |
There was a problem hiding this comment.
You can simplify this by initialising the variable and setting its value at the same time.
I.e.:
let totalStudentsAndMentors = numberOfStudents + numberOfMentors;
(so you no longer need line 4)
| message = `Number of students: ${numberOfStudents} | ||
| Number of mentors: ${numberOfMentors} | ||
| Total number of students and mentors: ${totalStudentsAndMentors}`; | ||
| console.log(message); No newline at end of file |
There was a problem hiding this comment.
Excellent. Again, you could do let message = on line 11 and define the variable at the same time as you set its value. This can sometimes be safer, as it means you'll get an error message saying the variable is undefined if you try to use it before it has been set correctly. This is helpful as then you'll know there's something wrong.
| return (result = number / 2); | ||
| } | ||
|
|
||
| var result = halve(12); |
|
Your coursework submission has been closed because nobody has interacted with it in six weeks. You are welcome to re-open it to get more feedback. |
Volunteers: Are you marking this coursework? You can find a guide on how to mark this coursework in
HOW_TO_MARK.mdin the root of this repositoryYour Details
Homework Details
Notes
What did you find easy?
What did you find hard?
What do you still not understand?
Any other notes?