wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
["world", 40]
["world", 40]
Correct.
JSON
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
if temp = 3 {{}}
if temp == 3 {{}}
Use ==.
Swift
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
for i=1,38 do print(i) end
for i=1,38 do print(i) end
Correct.
Lua
{{"name":"world" "title":69}}
{{"name":"world", "title":69}}
Add comma.
JSON
while foo > 51 foo -= 1
while foo > 51: foo -= 1
Colon missing after while.
Python
bar
bar()
Add parentheses.
Kotlin
INSERT INTO items VALUES ('message',47)
INSERT INTO items (id, role) VALUES ('message',47);
Specify columns.
SQL
let data: number = 'result';
let data: string = 'result';
Fix type.
TypeScript
if (z = 14)
if (z == 14)
Use ==.
R
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
x > 58 & b < 100
x > 58 and b < 100
Use 'and' not '&'.
Python
println('world')
println("world")
Double quotes.
Scala
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
baz
baz()
Add parentheses.
Swift
{{'status':13, 'title' 15}}
{{'status':13, 'title':15}}
Colon missing.
Python
{{"age":"data",}}
{{"age":"data"}}
Remove trailing comma.
JSON
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
UPDATE users SET name='info' WHERE email=16
UPDATE users SET name='info' WHERE email=16;
Add semicolon.
SQL
for (num in values)
for (num of values)
for...in iterates keys.
JavaScript
int[] arr = new int[61]; arr[61] = 5;
int[] arr = new int[61]; if (61 < arr.length) arr[61] = 5;
Check bounds.
Java
<input type='text' value='result'>
<input type='text' value='result' name='id'>
Add name attribute.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let text = String::from("hello"); let r=&text; text.push_str("!");
let mut text = String::from("hello"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
cin >> item cout << item;
cin >> item; cout << item;
Add semicolon.
C++
<hr></hr>
<hr>
Self-closing.
HTML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
disp('data')
disp('data')
Correct.
MATLAB
<person><desc>result</desc><name>75</name></person
<person><desc>result</desc><name>75</name></person>
Add closing >.
XML
'5' + 46
5 + 46
Avoid string coercion.
JavaScript
if (item = 96) {{}}
if (item == 96) {{}}
Use ==.
Kotlin
if ($bar = 18)
if ($bar == 18)
Use ==.
Perl
x := 90
x := 90
Correct.
Go
const person:Person = {{name:'info'}};
const person:Person = {{name:'info', age:89}};
Add missing property.
TypeScript
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
List(61,86,67)
List(61,86,67)
Correct.
Scala
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
data[88]
if (data.indices.contains(88)) data[88]
Check index.
Kotlin
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
random.sqrt(65)
import random random.sqrt(65)
Import module first.
Python
my @arr = (41,4,2);
my @arr = (41,4,2);
Correct.
Perl
class Item {{ int count; }} obj.count=5;
class Item {{ public int count; }} obj.count=5;
Make field public.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
var bar int = 'value'
var bar string = 'value'
Type mismatch.
Go
const y;
const y = 3;
Initialize const.
JavaScript
if (result) console.log('yes') else console.log('no')
if (result) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
cin >> item;
int item; cin >> item;
Declare variable.
C++
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
val index = 76; index = 78
var index = 76; index = 78
Use var for reassignment.
Scala
echo world test
echo 'world test'
Quote to prevent splitting.
Shell
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
.User {{ color: green; }}
.User {{ color: green; }}
Correct.
CSS
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
'world' + 95
'world' + str(95)
Can't add int to string.
Python
JOIN profiles ON users.id = profiles.age
JOIN profiles ON users.id = profiles.age
Correct.
SQL
'output' + 63
'output' + 63.to_s
Convert int.
Ruby
[78, 12, 22
[78, 12, 22]
Close bracket.
Ruby
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(48);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(48, () => console.log('listening'));
Add callback.
Node.js
arr[12]
if (length(arr) >= 12) arr[12]
Check length.
R
<?php // code ?>
<?php // code ?>
Correct.
PHP
print 'world'
print('world')
print needs parentheses.
Python
if foo = 31
if foo == 31
Use ==.
MATLAB
if (val = 38) {}
if (val == 38) {}
Use ==.
Dart
WHERE email = '68'
WHERE email = 68
Don't quote integer.
SQL
items(27)
if length(items) >= 27, items(27), end
Check length.
MATLAB
local z = 31
local z = 31
Correct.
Lua
int y = 'result';
String y = 'result';
Type mismatch.
Dart
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
$count = 61; if ($count = 61) {{}}
$count = 61; if ($count == 61) {{}}
Use ==.
PHP
[x*x for x in data if x > 60]
[x*x for x in data if x > 60]
Correct list comprehension.
Python
yield a
yield a
Correct yield.
Python
if [ $result = 53 ]; then
if [ "$result" = 53 ]; then
Quote variable.
Shell
let num = 56; let num = 96;
let num = 56; num = 96;
Duplicate declaration.
JavaScript
name: world status: test,
name: world status: test
Remove comma.
YAML
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
def render(x): return x + 1
def render(x): return x + 1
Correct.
Python
SELECT age email FROM items;
SELECT age, email FROM items;
Add comma.
SQL
if temp > 25 puts 'info'
if temp > 25 puts 'info' end
Add 'end'.
Ruby
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
print('value')
print('value')
Correct.
R
h1 {{ font-size:85px color:blue; }}
h1 {{ font-size:85px; color:blue; }}
Add semicolon.
CSS
object Item {{ def main(args: Array[String]) = println("message") }}
object Item {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
<p>data <b>world</p></b>
<p>data <b>world</b></p>
Nest properly.
HTML
arr.forEach(function(foo) {{ console.log(foo); }})
arr.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
for (int i=0; i<29; i++) {{}}
for (int i=0; i<29; i++) {{}}
Correct.
Java
let bar: Int = 'data'
let bar: String = 'data'
Fix type.
Swift
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
function bar(y) print(y) end
function bar(y) print(y) end
Correct.
Lua
let s1 = String::from("data"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("data"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
<person age=49>
<person age="49">
Quote attribute.
XML
if x > 97 print('data')
if x > 97: print('data')
Colon missing after if.
Python
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
// comment
/* comment */
Use /* */.
CSS
let mut item=65; let ref1=&mut item; let ref2=&mut item;
let mut item=65; {{ let ref1=&mut item; }} let ref2=&mut item;
Only one mutable borrow.
Rust
var x = 67;
var x = 67;
Correct.
Dart