-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyntax-in-programming-languages.js
78 lines (52 loc) · 1.5 KB
/
syntax-in-programming-languages.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
Objective:
Define “syntax” in your own words and practice identifying and
correcting syntax errors.
Introduction:
Write down your own definition of “syntax” as it relates to programming,
using examples from English grammar as an analogy.
Syntax Scavenger Hunt:
Some of these snippets are written correctly,
while others will contain deliberate syntax errors,
such as missing parentheses, misplaced semicolons,
incorrect variable names, or unmatched braces.
1. Correct Example:
let greeting = "Hello";
console.log(greeting);
2. Missing Parenthesis:
console.log("This line has a missing parenthesis";
3. Unmatched Braces:
function sayHello(name) {
if (name) {
console.log("Hello, " + name);
// Missing closing brace for function
4. Incorrect Variable Name (Variables must be declared before use):
myNumber = 10;
console.log(myNumber);
5. Extra Semicolon:
let x = 5;;
console.log(x);
6. Unclosed String:
let message = "Missing the end quote;
console.log(message);
7. Correct Example:
const sum = 2 + 2;
console.log("The sum is: " + sum);
8. Misplaced Bracket:
let fruits = ["apple", "banana", "cherry";
console.log(fruits);
9. Incorrect Keyword Spelling:
functon greet() {
console.log("Hello!");
}
greet();
10. Correct Example:
let isRaining = false;
if (!isRaining) {
console.log("It's not raining, let's go outside!");
}
For each snippet:
Identify if the code has a syntax error.
If it does, state the error and explain why it’s incorrect.
Propose a corrected version of the snippet.
*/