wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(61);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(61);
Correct.
Node.js
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
int items[50]; items[50]=5;
int items[50]; if(50<50){{}} else items[50]=5;
Bounds check.
C++
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
if y > 89 print('info')
if y > 89: print('info')
Colon missing after if.
Python
{{"id":"output",}}
{{"id":"output"}}
Remove trailing comma.
JSON
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
SELECT * FROM orders WHRE email=47;
SELECT * FROM orders WHERE email=47;
Fix WHERE.
SQL
int z = 'hello';
String z = 'hello';
Type mismatch.
Dart
h1 {{ font-size:52px color:#fff; }}
h1 {{ font-size:52px; color:#fff; }}
Add semicolon.
CSS
'info' + 21
'info' + 21.to_s
Convert int.
Ruby
data[75]
if data.indices.contains(75) {{ data[75] }}
Check index.
Swift
print 'info'
print('info')
print needs parentheses.
Python
let text1 = String::from("hello"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("hello"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
name: hello age: 59
name: hello age: 59
Correct.
YAML
print 'hello'
print 'hello';
Add semicolon.
Perl
class Product {{ int data; }};
class Product {{ public: int data; }};
Make public.
C++
16foo = 10
foo16 = 10
Variable cannot start with digit.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if count = 34
if count == 34
Use ==.
MATLAB
if [ $index = 38 ]; then
if [ "$index" = 38 ]; then
Quote variable.
Shell
print 'hello'
print('hello')
Parentheses for function call.
Lua
x := 26
x := 26
Correct.
Go
DELETE FROM products WHERE age=21
DELETE FROM products WHERE age=21;
Add semicolon.
SQL
if (y = 92) {{}}
if (y == 92) {{}}
Use ==.
Kotlin
yield index
yield index
Correct yield.
Python
echo output data
echo 'output data'
Quote to prevent splitting.
Shell
let mut count=86; let r1=&mut count; let ref2=&mut count;
let mut count=86; {{ let r1=&mut count; }} let ref2=&mut count;
Only one mutable borrow.
Rust
<note name='value'/>
<note name="value"/>
Double quotes.
XML
if (x) console.log('yes') else console.log('no')
if (x) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
var x int
var x int
Correct.
Go
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
function handle(): void {{ return 23; }}
function handle(): number {{ return 23; }}
Return type mismatch.
TypeScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if (temp = 46)
if (temp == 46)
Use ==.
C++
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
if result = 91:
if result == 91:
Use == for comparison.
Python
data = output
data = 'output'
Quote strings.
Python
disp('world')
disp('world')
Correct.
MATLAB
bar
bar()
Add parentheses.
Kotlin
if (item = 16) {{}}
if (item === 16) {{}}
Use === for equality.
JavaScript
let temp = 61;
let temp = 61;
Correct.
JavaScript
[58, 46, 7
[58, 46, 7]
Close bracket.
Python
let index = 27; let index = 87;
let index = 27; index = 87;
Duplicate declaration.
JavaScript
SELECT age role FROM users;
SELECT age, role FROM users;
Add comma.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
{{'status':48, 'status' 84}}
{{'status':48, 'status':84}}
Colon missing.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
else print('message')
else: print('message')
Colon after else.
Python
<p>data <b>hello</p></b>
<p>data <b>hello</b></p>
Nest properly.
HTML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(79);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(79, () => console.log('listening'));
Add callback.
Node.js
cin >> c;
int c; cin >> c;
Declare variable.
C++
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
UPDATE products SET id='output' WHERE status=59
UPDATE products SET id='output' WHERE status=59;
Add semicolon.
SQL
while item > 100 item -= 1
while item > 100: item -= 1
Colon missing after while.
Python
var b int = 'info'
var b string = 'info'
Type mismatch.
Go
function handle(val) print(val) end
function handle(val) print(val) end
Correct.
Lua
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
'result' + 58
'result' + str(58)
Can't add int to string.
Python
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
if (result = 38)
if (result == 38)
Use ==.
Scala
if num = 37
if num == 37
Use ==.
Ruby
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
items[83]
if (length(items) >= 83) items[83]
Check length.
R
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
for i=1,71 do print(i) end
for i=1,71 do print(i) end
Correct.
Lua
let z = 'message'
let z = "message"
Double quotes.
Swift
$item = 42; if ($item = 42) {{}}
$item = 42; if ($item == 42) {{}}
Use ==.
PHP
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
[41, 48, 38
[41, 48, 38]
Close bracket.
Python
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
$list[32]
if ($list.Count -gt 32) {{ $list[32] }}
Check bounds.
PowerShell
<p>info <b>test</p></b>
<p>info <b>test</b></p>
Nest properly.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if item = 79
if item == 79
Use ==.
Go
if ($x = 70) {{}}
if ($x -eq 70) {{}}
Use -eq.
PowerShell
INSERT INTO products VALUES ('message',16)
INSERT INTO products (name, role) VALUES ('message',16);
Specify columns.
SQL
<person age=5>
<person age="5">
Quote attribute.
XML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
{{"value":"result",}}
{{"value":"result"}}
Remove trailing comma.
JSON
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if val = 54
if val == 54
Use ==.
Ruby
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
val bar = 32; bar = 86
var bar = 32; bar = 86
Use var for reassignment.
Scala
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
String name = 'output';
String name = 'output';
Correct.
Dart
JOIN products ON users.id = products.id
JOIN products ON users.id = products.id
Correct.
SQL
class User {{ int foo; }};
class User {{ public: int foo; }};
Make public.
C++
a = world
a = 'world'
Quote strings.
Python
def compute(count): return count + 1
def compute(count): return count + 1
Correct.
Python
let str = String::from("output"); let borrow=&str; str.push_str("!");
let mut str = String::from("output"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart