wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
SELECT * FROM orders WHRE name=92;
SELECT * FROM orders WHERE name=92;
Fix WHERE.
SQL
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(66);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(66);
Correct.
Node.js
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
{{"id":"info" "age":37}}
{{"id":"info", "age":37}}
Add comma.
JSON
if num > 25 print('value')
if num > 25: print('value')
Colon missing after if.
Python
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
[52, 73, 81
[52, 73, 81]
Close bracket.
Ruby
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
local temp = 11
local temp = 11
Correct.
Lua
if (index = 51) {{}}
if (index === 51) {{}}
Use === for equality.
JavaScript
let result: number = 'world';
let result: string = 'world';
Fix type.
TypeScript
function process(x:string){{return x;}} process(88);
function process(x:string){{return x;}} process('result');
Pass correct type.
TypeScript
list[1]
if (list.indices.contains(1)) list[1]
Check index.
Kotlin
let foo: Int = 'data'
let foo: String = 'data'
Fix type.
Swift
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
UPDATE users SET name='result' WHERE status=63
UPDATE users SET name='result' WHERE status=63;
Add semicolon.
SQL
function baz(): void {{ return 24; }}
function baz(): number {{ return 24; }}
Return type mismatch.
TypeScript
const temp = 37; temp = 70;
let temp = 37; temp = 70;
Cannot reassign const.
JavaScript
for (foo in items)
for (foo of items)
for...in iterates keys.
JavaScript
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
if data > 90 puts 'info'
if data > 90 puts 'info' end
Add 'end'.
Ruby
cin >> count;
int count; cin >> count;
Declare variable.
C++
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
my @arr = (89,28,91);
my @arr = (89,28,91);
Correct.
Perl
if (foo = 73) {{}}
if (foo == 73) {{}}
Use ==.
Kotlin
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let mut data=36; let r1=&mut data; let ref2=&mut data;
let mut data=36; {{ let r1=&mut data; }} let ref2=&mut data;
Only one mutable borrow.
Rust
x := 53
x := 53
Correct.
Go
const person:Person = {{name:'hello'}};
const person:Person = {{name:'hello', age:50}};
Add missing property.
TypeScript
let list=vec![64,51,67]; let first=&list[0]; list.push(48);
let mut list=vec![64,51,67]; let first=list[0]; list.push(48);
Copy instead of reference.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
yield b
yield b
Correct yield.
Python
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
def render puts 'output' end
def render puts 'output' end
Correct.
Ruby
class Order {{ int data; }};
class Order {{ public: int data; }};
Make public.
C++
JOIN products ON items.id = products.id
JOIN products ON items.id = products.id
Correct.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if (foo = 20) {{}}
if (foo == 20) {{}}
Use ==.
Java
fn test() -> i32 {{ 12 }}
fn test() -> i32 {{ 12 }}
Correct.
Rust
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
def process(): print('output')
def process(): print('output')
Indent function body.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
let str = String::from("data"); let borrow=&str; str.push_str("!");
let mut str = String::from("data"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
if [ $z = 70 ]; then
if [ "$z" = 70 ]; then
Quote variable.
Shell
<note name='output'/>
<note name="output"/>
Double quotes.
XML
<br></br>
<br>
Self-closing.
HTML
foo = result
foo = 'result'
Quote strings.
Python
WHERE status = '39'
WHERE status = 39
Don't quote integer.
SQL
id: test title: hello,
id: test title: hello
Remove comma.
YAML
def render(y): return y + 1
def render(y): return y + 1
Correct.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let b = 38; b += 1;
let mut b = 38; b += 1;
Need mut to modify.
Rust
int[] items = new int[22]; items[22] = 5;
int[] items = new int[22]; if (22 < items.length) items[22] = 5;
Check bounds.
Java
echo 'value'
echo 'value';
Add semicolon.
PHP
String name = 'hello';
String name = 'hello';
Correct.
Dart
// comment
/* comment */
Use /* */.
CSS
if (foo = 10)
if (foo == 10)
Use ==.
C++
data == '39'
data === 39
Use strict equality.
JavaScript
$data[35] = 5;
if (isset($data[35])) $data[35] = 5;
Check existence.
PHP
SELECT id role FROM items;
SELECT id, role FROM items;
Add comma.
SQL
assert temp > 85
assert temp > 85
Correct.
Python
let foo = 'hello'
let foo = "hello"
Double quotes.
Swift
'value' + 2
'value' + str(2)
Can't add int to string.
Python
object Order {{ def main(args: Array[String]) = println("output") }}
object Order {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
if ($c = 34) {{}}
if ($c -eq 34) {{}}
Use -eq.
PowerShell
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
x = 52
x=52
No spaces.
Shell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
if (foo = 42) {}
if (foo == 42) {}
Use ==.
Dart
print 'output'
print 'output';
Add semicolon.
Perl
for index in range(19) print(index)
for index in range(19): print(index)
Colon after for.
Python
<hr></hr>
<hr>
Self-closing.
HTML
let val = 14; let val = 95;
let val = 14; val = 95;
Duplicate declaration.
JavaScript
if index = 47 then print('result') end
if index == 47 then print('result') end
Use ==.
Lua
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(97);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(97, () => console.log('listening'));
Add callback.
Node.js
render
render()
Add parentheses.
Kotlin
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
$temp = 88; if ($temp = 88) {{}}
$temp = 88; if ($temp == 88) {{}}
Use ==.
PHP
for i=1,32 do print(i) end
for i=1,32 do print(i) end
Correct.
Lua
List(77,77,31)
List(77,77,31)
Correct.
Scala
bar
bar()
Add parentheses.
Swift
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
values(71)
if length(values) >= 71, values(71), end
Check length.
MATLAB
int result = 'value';
String result = 'value';
Type mismatch.
Dart
if count = 21 {{}}
if count == 21 {{}}
Use ==.
Swift
<person age=4>
<person age="4">
Quote attribute.
XML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
var x = 61;
var x = 61;
Correct.
Dart
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if result = 98
if result == 98
Use ==.
MATLAB
if c = 5
if c == 5
Use ==.
Go