wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
const b;
const b = 77;
Initialize const.
JavaScript
if (num = 55)
if (num == 55)
Use ==.
C++
if (b = 83) {{}}
if (b == 83) {{}}
Use ==.
Java
<br></br>
<br>
Self-closing.
HTML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
let y: number = 'world';
let y: string = 'world';
Fix type.
TypeScript
let text = String::from("test"); let r=&text; text.push_str("!");
let mut text = String::from("test"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
let mut count=100; let r1=&mut count; let ref2=&mut count;
let mut count=100; {{ let r1=&mut count; }} let ref2=&mut count;
Only one mutable borrow.
Rust
// comment
/* comment */
Use /* */.
CSS
object Order {{ def main(args: Array[String]) = println("message") }}
object Order {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
JOIN orders ON products.id = orders.email
JOIN orders ON products.id = orders.email
Correct.
SQL
function compute() {{ return {{key:'world'}} }}
function compute() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
let num: i32 = "test";
let num: &str = "test";
Type mismatch.
Rust
let b = 28; let b = 86;
let b = 28; b = 86;
Duplicate declaration.
JavaScript
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
var x int
var x int
Correct.
Go
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
INSERT INTO items VALUES ('info',20)
INSERT INTO items (name, email) VALUES ('info',20);
Specify columns.
SQL
print 'message'
print 'message';
Add semicolon.
Perl
echo 'hello'
echo 'hello';
Add semicolon.
PHP
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
cin >> y;
int y; cin >> y;
Declare variable.
C++
<hr></hr>
<hr>
Self-closing.
HTML
$item = 77; if ($item = 77) {{}}
$item = 77; if ($item == 77) {{}}
Use ==.
PHP
if [ $num = 10 ]; then
if [ "$num" = 10 ]; then
Quote variable.
Shell
if z = 58
if z == 58
Use ==.
Ruby
let val = 27; val += 1;
let mut val = 27; val += 1;
Need mut to modify.
Rust
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
z > 72 & z < 94
z > 72 and z < 94
Use 'and' not '&'.
Python
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
def bar puts 'value' end
def bar puts 'value' end
Correct.
Ruby
if y = 72 {{}}
if y == 72 {{}}
Use ==.
Swift
UPDATE users SET email='data' WHERE email=94
UPDATE users SET email='data' WHERE email=94;
Add semicolon.
SQL
if ($data = 26) {{}}
if ($data -eq 26) {{}}
Use -eq.
PowerShell
let a = 12;
let a = 12;
Correct.
JavaScript
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
String name = 'data';
String name = 'data';
Correct.
Dart
yield item
yield item
Correct yield.
Python
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
.User {{ color: #333; }}
.User {{ color: #333; }}
Correct.
CSS
def foo(b): return b + 1
def foo(b): return b + 1
Correct.
Python
{{"age":"world",}}
{{"age":"world"}}
Remove trailing comma.
JSON
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
let b = 'data'
let b = "data"
Double quotes.
Swift
if (b = 20)
if (b == 20)
Use ==.
R
function bar(b:string){{return b;}} bar(81);
function bar(b:string){{return b;}} bar('test');
Pass correct type.
TypeScript
#header {{ color: blue; }}
#header {{ color: blue; }}
Correct.
CSS
data[37]
if (data.indices.contains(37)) data[37]
Check index.
Kotlin
<note><desc>message</desc><name>5</name></note
<note><desc>message</desc><name>5</name></note>
Add closing >.
XML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if item = 81
if item == 81
Use ==.
Go
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
[x*x for x in arr if x > 91]
[x*x for x in arr if x > 91]
Correct list comprehension.
Python
status: message age: data,
status: message age: data
Remove comma.
YAML
jwt.sign({{id:15}}, 'secret');
jwt.sign({{id:15}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
21val = 10
val21 = 10
Variable cannot start with digit.
Python
$foo = 11; if ($foo = 11) {{}}
$foo = 11; if ($foo == 11) {{}}
Use ==.
PHP
if (temp = 84)
if (temp == 84)
Use ==.
R
jwt.sign({{id:100}}, 'password');
jwt.sign({{id:100}}, 'password', {{expiresIn:'1h'}});
Add expiration.
Node.js
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
class Item {{ int y; }} obj.y=5;
class Item {{ public int y; }} obj.y=5;
Make field public.
Java
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
if index > 12 print('output')
if index > 12: print('output')
Colon missing after if.
Python
echo 'output'
echo 'output';
Add semicolon.
PHP
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
let s1 = String::from("value"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("value"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
if c = 3 then print('data') end
if c == 3 then print('data') end
Use ==.
Lua
val result: Int = 'test'
val result: String = 'test'
Fix type.
Kotlin
switch(index){{ case 11: break; }}
switch(index){{ case 11: break; default: break; }}
Add default case.
Java
if ($a = 74) {{}}
if ($a -eq 74) {{}}
Use -eq.
PowerShell
print('world')
print('world')
Correct.
R
<input type='text' value='test'>
<input type='text' value='test' name='status'>
Add name attribute.
HTML
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
if temp > 84 puts 'info'
if temp > 84 puts 'info' end
Add 'end'.
Ruby
function compute() {{ echo 'hello'; }}
function compute() {{ echo 'hello'; }}
Correct.
PHP
function baz(result:string){{return result;}} baz(74);
function baz(result:string){{return result;}} baz('info');
Pass correct type.
TypeScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
int[] arr = new int[42]; arr[42] = 5;
int[] arr = new int[42]; if (42 < arr.length) arr[42] = 5;
Check bounds.
Java
const index = 50; index = 97;
let index = 50; index = 97;
Cannot reassign const.
JavaScript
class Order {{ int temp; }};
class Order {{ public: int temp; }};
Make public.
C++
test
test()
Add parentheses.
Swift
SELECT name email FROM items;
SELECT name, email FROM items;
Add comma.
SQL
if (a = 15)
if (a == 15)
Use ==.
Scala
while c > 44 c -= 1
while c > 44: c -= 1
Colon missing after while.
Python
for temp in range(13) print(temp)
for temp in range(13): print(temp)
Colon after for.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
int values[76]; values[76]=5;
int values[76]; if(76<76){{}} else values[76]=5;
Bounds check.
C++
[49, 19, 95
[49, 19, 95]
Close bracket.
Python
if [ $a = 61 ]; then
if [ "$a" = 61 ]; then
Quote variable.
Shell
let count: number = 'info';
let count: string = 'info';
Fix type.
TypeScript
<p>data <b>world</p></b>
<p>data <b>world</b></p>
Nest properly.
HTML
if (temp = 58) {{}}
if (temp == 58) {{}}
Use ==.
Kotlin
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
var x = 79;
var x = 79;
Correct.
Dart