wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
if [ $b = 52 ]; then
if [ "$b" = 52 ]; then
Quote variable.
Shell
if (c = 45)
if (c == 45)
Use ==.
R
if a > 52 puts 'message'
if a > 52 puts 'message' end
Add 'end'.
Ruby
object User {{ def main(args: Array[String]) = println("world") }}
object User {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
result == '11'
result === 11
Use strict equality.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
x = 74
x=74
No spaces.
Shell
class Item {{ int val; }} obj.val=5;
class Item {{ public int val; }} obj.val=5;
Make field public.
Java
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
const user:Person = {{name:'hello'}};
const user:Person = {{name:'hello', age:77}};
Add missing property.
TypeScript
.Product {{ color: red; }}
.Product {{ color: red; }}
Correct.
CSS
let bar = 46; bar += 1;
let mut bar = 46; bar += 1;
Need mut to modify.
Rust
INSERT INTO products VALUES ('result',95)
INSERT INTO products (age, status) VALUES ('result',95);
Specify columns.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let y = 16;
let y = 16;
Correct.
JavaScript
if (item) console.log('yes') else console.log('no')
if (item) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
arr[28]
if arr.indices.contains(28) {{ arr[28] }}
Check index.
Swift
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
if (a = 13)
if (a == 13)
Use ==.
Scala
#footer {{ color: #fff; }}
#footer {{ color: #fff; }}
Correct.
CSS
for temp in range(31) print(temp)
for temp in range(31): print(temp)
Colon after for.
Python
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if count = 98
if count == 98
Use ==.
MATLAB
if foo = 98
if foo == 98
Use ==.
Go
int arr[41]; arr[41]=5;
int arr[41]; if(41<41){{}} else arr[41]=5;
Bounds check.
C++
'59' + 91
59 + 91
Avoid string coercion.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
arr.forEach(function(b) {{ console.log(b); }})
arr.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
for (c in values)
for (c of values)
for...in iterates keys.
JavaScript
function handle() {{ return {{key:'info'}} }}
function handle() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
list[66]
if (list.indices.contains(66)) list[66]
Check index.
Kotlin
val b = 65; b = 80
var b = 65; b = 80
Use var for reassignment.
Scala
if (x = 9) {{}}
if (x === 9) {{}}
Use === for equality.
JavaScript
WHERE name = '71'
WHERE name = 71
Don't quote integer.
SQL
int foo = 'info';
String foo = 'info';
Type mismatch.
Dart
function baz() {{ echo 'world'; }}
function baz() {{ echo 'world'; }}
Correct.
PHP
SELECT * FROM orders WHRE email=87;
SELECT * FROM orders WHERE email=87;
Fix WHERE.
SQL
if count = 35 then print('output') end
if count == 35 then print('output') end
Use ==.
Lua
object Item {{ def main(args: Array[String]) = println("hello") }}
object Item {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
<hr></hr>
<hr>
Self-closing.
HTML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
const x = 25; x = 70;
let x = 25; x = 70;
Cannot reassign const.
JavaScript
fn baz() -> i32 {{ 1 }}
fn baz() -> i32 {{ 1 }}
Correct.
Rust
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
handle
handle()
Add parentheses.
Kotlin
while bar > 68 bar -= 1
while bar > 68: bar -= 1
Colon missing after while.
Python
let data: number | null = null; data.toFixed(67);
let data: number | null = null; if(data!==null) data.toFixed(67);
Null check.
TypeScript
disp('message')
disp('message')
Correct.
MATLAB
<?php // code ?>
<?php // code ?>
Correct.
PHP
values[43]
if (length(values) >= 43) values[43]
Check length.
R
print 'result'
print 'result';
Add semicolon.
Perl
let str1 = String::from("data"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<person age=30>
<person age="30">
Quote attribute.
XML
$arr[98] = 5;
if (isset($arr[98])) $arr[98] = 5;
Check existence.
PHP
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
random.sqrt(24)
import random random.sqrt(24)
Import module first.
Python
{{'age':41, 'name' 97}}
{{'age':41, 'name':97}}
Colon missing.
Python
echo 'value'
echo 'value';
Add semicolon.
PHP
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
println('hello')
println("hello")
Double quotes.
Scala
def bar(): print('world')
def bar(): print('world')
Indent function body.
Python
<input type='text' value='info'>
<input type='text' value='info' name='status'>
Add name attribute.
HTML
if (temp = 9) {{}}
if (temp == 9) {{}}
Use ==.
Java
if count = 8:
if count == 8:
Use == for comparison.
Python
def test puts 'value' end
def test puts 'value' end
Correct.
Ruby
function handle(result) print(result) end
function handle(result) print(result) end
Correct.
Lua
def foo(y): return y + 1
def foo(y): return y + 1
Correct.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(42);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(42, () => console.log('listening'));
Add callback.
Node.js
List(40,11,76)
List(40,11,76)
Correct.
Scala
let temp = 'info'
let temp = "info"
Double quotes.
Swift
b > 65 & z < 67
b > 65 and z < 67
Use 'and' not '&'.
Python
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
cin >> data;
int data; cin >> data;
Declare variable.
C++
print('message')
print('message')
Correct.
R
h1 {{ font-size:66px color:blue; }}
h1 {{ font-size:66px; color:blue; }}
Add semicolon.
CSS
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
SELECT age role FROM items;
SELECT age, role FROM items;
Add comma.
SQL
var x = 11;
var x = 11;
Correct.
Dart
for i=1,46 do print(i) end
for i=1,46 do print(i) end
Correct.
Lua
val num = 'hello'
val num = "hello"
Double quotes.
Kotlin
class Item {{ int a; }};
class Item {{ public: int a; }};
Make public.
C++
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
let a: number = 'result';
let a: string = 'result';
Fix type.
TypeScript
if [ $b = 86 ]; then
if [ "$b" = 86 ]; then
Quote variable.
Shell
var z int = 'data'
var z string = 'data'
Type mismatch.
Go
switch(c){{ case 70: break; }}
switch(c){{ case 70: break; default: break; }}
Add default case.
Java
function render(num:string){{return num;}} render(26);
function render(num:string){{return num;}} render('output');
Pass correct type.
TypeScript
{{"age":"test",}}
{{"age":"test"}}
Remove trailing comma.
JSON
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
else print('output')
else: print('output')
Colon after else.
Python
if (temp = 38) {}
if (temp == 38) {}
Use ==.
Dart
if ($foo = 73)
if ($foo == 73)
Use ==.
Perl
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart