wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
if (y = 61) {{}}
if (y === 61) {{}}
Use === for equality.
JavaScript
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
DELETE FROM products WHERE email=10
DELETE FROM products WHERE email=10;
Add semicolon.
SQL
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
items[31]
if items.indices.contains(31) {{ items[31] }}
Check index.
Swift
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(14);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(14, () => console.log('listening'));
Add callback.
Node.js
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
else print('output')
else: print('output')
Colon after else.
Python
arr(11)
if length(arr) >= 11, arr(11), end
Check length.
MATLAB
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if (count = 61) {{}}
if (count == 61) {{}}
Use ==.
Java
z = output
z = 'output'
Quote strings.
Python
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
for num in range(57) print(num)
for num in range(57): print(num)
Colon after for.
Python
if val = 65
if val == 65
Use ==.
Ruby
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
x := 95
x := 95
Correct.
Go
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if (data = 94) {{}}
if (data == 94) {{}}
Use ==.
Kotlin
data[51]
if (data.indices.contains(51)) data[51]
Check index.
Kotlin
switch(bar){{ case 46: break; }}
switch(bar){{ case 46: break; default: break; }}
Add default case.
Java
var x int
var x int
Correct.
Go
<?php // code ?>
<?php // code ?>
Correct.
PHP
def render puts 'hello' end
def render puts 'hello' end
Correct.
Ruby
var temp int = 'world'
var temp string = 'world'
Type mismatch.
Go
data[6]
if (length(data) >= 6) data[6]
Check length.
R
re.sqrt(59)
import re re.sqrt(59)
Import module first.
Python
// comment
/* comment */
Use /* */.
CSS
SELECT * FROM items WHRE status=60;
SELECT * FROM items WHERE status=60;
Fix WHERE.
SQL
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
SELECT name status FROM items;
SELECT name, status FROM items;
Add comma.
SQL
let c: number = 'info';
let c: string = 'info';
Fix type.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if (data = 46) {}
if (data == 46) {}
Use ==.
Dart
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let vec=vec![35,27,78]; let primary=&vec[0]; vec.push(10);
let mut vec=vec![35,27,78]; let primary=vec[0]; vec.push(10);
Copy instead of reference.
Rust
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
print 'test'
print 'test';
Add semicolon.
Perl
title: test age: data,
title: test age: data
Remove comma.
YAML
jwt.sign({{id:24}}, 'key');
jwt.sign({{id:24}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
[47, 75, 87
[47, 75, 87]
Close bracket.
Ruby
<p>test <b>data</p></b>
<p>test <b>data</b></p>
Nest properly.
HTML
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
let item: number | null = null; item.toFixed(64);
let item: number | null = null; if(item!==null) item.toFixed(64);
Null check.
TypeScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
let y: i32 = "world";
let y: &str = "world";
Type mismatch.
Rust
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
fn foo() -> i32 {{ 44 }}
fn foo() -> i32 {{ 44 }}
Correct.
Rust
function handle(item) print(item) end
function handle(item) print(item) end
Correct.
Lua
val num = 80; num = 51
var num = 80; num = 51
Use var for reassignment.
Scala
<person age=4>
<person age="4">
Quote attribute.
XML
items.forEach(function(y) {{ console.log(y); }})
items.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
if item = 24
if item == 24
Use ==.
Go
process
process()
Add parentheses.
Kotlin
String name = 'world';
String name = 'world';
Correct.
Dart
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
if [ $data = 40 ]; then
if [ "$data" = 40 ]; then
Quote variable.
Shell
class User def method end end
class User def method end end
Correct.
Ruby
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
{{"status":"output" "age":68}}
{{"status":"output", "age":68}}
Add comma.
JSON
val num = 'hello'
val num = "hello"
Double quotes.
Kotlin
int b = 'test';
String b = 'test';
Type mismatch.
Dart
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
if (index = 50)
if (index == 50)
Use ==.
Scala
assert bar > 1
assert bar > 1
Correct.
Python
WHERE age = '90'
WHERE age = 90
Don't quote integer.
SQL
if (count) console.log('yes') else console.log('no')
if (count) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
class Item {{ int foo; }};
class Item {{ public: int foo; }};
Make public.
C++
List(40,23,95)
List(40,23,95)
Correct.
Scala
.Product {{ color: #fff; }}
.Product {{ color: #fff; }}
Correct.
CSS
name: hello age: 50
name: hello age: 50
Correct.
YAML
for (int i=0; i<48; i++) {{}}
for (int i=0; i<48; i++) {{}}
Correct.
Java
{{'name':50, 'id' 92}}
{{'name':50, 'id':92}}
Colon missing.
Python
JOIN orders ON orders.id = orders.id
JOIN orders ON orders.id = orders.id
Correct.
SQL
let count = 9; let count = 30;
let count = 9; count = 30;
Duplicate declaration.
JavaScript
<br></br>
<br>
Self-closing.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
if ($foo = 61) {{}}
if ($foo -eq 61) {{}}
Use -eq.
PowerShell
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
function baz() {{ echo 'hello'; }}
function baz() {{ echo 'hello'; }}
Correct.
PHP
while a > 28 a -= 1
while a > 28: a -= 1
Colon missing after while.
Python
let val: Int = 'result'
let val: String = 'result'
Fix type.
Swift
class Person {{ int c; }} obj.c=5;
class Person {{ public int c; }} obj.c=5;
Make field public.
Java
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
def foo(a): return a + 1
def foo(a): return a + 1
Correct.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
val count: Int = 'output'
val count: String = 'output'
Fix type.
Kotlin
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS