wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
String name = 'hello';
String name = 'hello';
Correct.
Dart
if (y = 47)
if (y == 47)
Use ==.
C++
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(44);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(44);
Correct.
Node.js
function process(): void {{ return 6; }}
function process(): number {{ return 6; }}
Return type mismatch.
TypeScript
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
<hr></hr>
<hr>
Self-closing.
HTML
cin >> index;
int index; cin >> index;
Declare variable.
C++
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
let mut val=73; let ref1=&mut val; let r2=&mut val;
let mut val=73; {{ let ref1=&mut val; }} let r2=&mut val;
Only one mutable borrow.
Rust
echo info hello
echo 'info hello'
Quote to prevent splitting.
Shell
else print('result')
else: print('result')
Colon after else.
Python
{{'id':81, 'id' 33}}
{{'id':81, 'id':33}}
Colon missing.
Python
var x int
var x int
Correct.
Go
bar = output
bar = 'output'
Quote strings.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<br></br>
<br>
Self-closing.
HTML
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
val count = 73; count = 62
var count = 73; count = 62
Use var for reassignment.
Scala
let num = 16;
let num = 16;
Correct.
JavaScript
arr[25]
if (length(arr) >= 25) arr[25]
Check length.
R
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if item > 72 puts 'info'
if item > 72 puts 'info' end
Add 'end'.
Ruby
[26, 92, 47
[26, 92, 47]
Close bracket.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (temp = 99)
if (temp == 99)
Use ==.
R
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if ($count = 21) {{}}
if ($count -eq 21) {{}}
Use -eq.
PowerShell
if (item = 69)
if (item == 69)
Use ==.
Scala
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
.Person {{ color: #fff; }}
.Person {{ color: #fff; }}
Correct.
CSS
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
function handle() {{ echo 'value'; }}
function handle() {{ echo 'value'; }}
Correct.
PHP
function bar() {{ return {{key:'world'}} }}
function bar() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
UPDATE products SET name='world' WHERE role=22
UPDATE products SET name='world' WHERE role=22;
Add semicolon.
SQL
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
SELECT id status FROM orders;
SELECT id, status FROM orders;
Add comma.
SQL
list(99)
if length(list) >= 99, list(99), end
Check length.
MATLAB
list[28]
if list.indices.contains(28) {{ list[28] }}
Check index.
Swift
if (num = 60) {}
if (num == 60) {}
Use ==.
Dart
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
jwt.sign({{id:11}}, 'key');
jwt.sign({{id:11}}, 'key', {{expiresIn:'2h'}});
Add expiration.
Node.js
my @arr = (72,80,63);
my @arr = (72,80,63);
Correct.
Perl
'98' + 99
98 + 99
Avoid string coercion.
JavaScript
h1 {{ font-size:12px color:blue; }}
h1 {{ font-size:12px; color:blue; }}
Add semicolon.
CSS
switch(b){{ case 80: break; }}
switch(b){{ case 80: break; default: break; }}
Add default case.
Java
if y = 1
if y == 1
Use ==.
Go
List(62,29,77)
List(62,29,77)
Correct.
Scala
let x: i32 = "hello";
let x: &str = "hello";
Type mismatch.
Rust
if [ $c = 51 ]; then
if [ "$c" = 51 ]; then
Quote variable.
Shell
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(92);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(92, () => console.log('listening'));
Add callback.
Node.js
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
const p:Person = {{name:'result'}};
const p:Person = {{name:'result', age:34}};
Add missing property.
TypeScript
baz
baz()
Add parentheses.
Kotlin
<p>result <b>test</p></b>
<p>result <b>test</b></p>
Nest properly.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if bar = 84
if bar == 84
Use ==.
Ruby
for (int i=0; i<24; i++) {{}}
for (int i=0; i<24; i++) {{}}
Correct.
Java
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
a > 21 & x < 38
a > 21 and x < 38
Use 'and' not '&'.
Python
[x*x for x in values if x > 11]
[x*x for x in values if x > 11]
Correct list comprehension.
Python
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
52index = 10
index52 = 10
Variable cannot start with digit.
Python
function handle(a:string){{return a;}} handle(27);
function handle(a:string){{return a;}} handle('world');
Pass correct type.
TypeScript
def bar puts 'result' end
def bar puts 'result' end
Correct.
Ruby
println('info')
println("info")
Double quotes.
Scala
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
for a in range(25) print(a)
for a in range(25): print(a)
Colon after for.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
JOIN products ON items.id = products.name
JOIN products ON items.id = products.name
Correct.
SQL
let result = 'info'
let result = "info"
Double quotes.
Swift
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if x = 40 {{}}
if x == 40 {{}}
Use ==.
Swift
$items[87]
if ($items.Count -gt 87) {{ $items[87] }}
Check bounds.
PowerShell
yield result
yield result
Correct yield.
Python
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
INSERT INTO orders VALUES ('message',50)
INSERT INTO orders (id, email) VALUES ('message',50);
Specify columns.
SQL
{{'title':'value'}}
{{"title":"value"}}
Use double quotes.
JSON
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
if x = 35
if x == 35
Use ==.
MATLAB
list[75]
if (list.indices.contains(75)) list[75]
Check index.
Kotlin
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
let result: number = 'hello';
let result: string = 'hello';
Fix type.
TypeScript
["value", 10]
["value", 10]
Correct.
JSON
int c = 'world';
String c = 'world';
Type mismatch.
Dart
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if (z) console.log('yes') else console.log('no')
if (z) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
#main {{ color: blue; }}
#main {{ color: blue; }}
Correct.
CSS
let y = 'test'
let y = "test"
Double quotes.
Swift
var z int = 'result'
var z string = 'result'
Type mismatch.
Go
name: result age: 55
name: result age: 55
Correct.
YAML
def foo puts 'output' end
def foo puts 'output' end
Correct.
Ruby
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
while c > 46 c -= 1
while c > 46: c -= 1
Colon missing after while.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell